javascript¼Ì³Ð·½Ê½Ö®Ò»
ÃæÏò¶ÔÏóµÄÓïÑÔ¶àÊý¶¼Ö§³Ö¼Ì³Ð£¬¼Ì³Ð×îÖØÒªµÄÓŵã¾ÍÊÇ´úÂ븴Ó㬴Ӷø¹¹½¨´óÐÍÈí¼þϵͳ¡£Èç¹ûÒ»¸öÀàÄܹ»ÖØÓÃÁíÒ»¸öÀàµÄÊôÐԺͻò·½·¨£¬¾Í³ÆÖ®Îª¼Ì³Ð¡£
´ÓÕâ¸ö½Ç¶ÈÀ´¿´¿´jsµÄ¼Ì³Ð·½Ê½¡£jsÖм̳з½Ê½ÓëдÀ෽ʽϢϢÏà¹Ø¡£²»Í¬µÄдÀ෽ʽÔì³É²»Í¬µÄ¼Ì³Ð·½Ê½¡£¸÷ÖÖÁ÷ÐÐjs¿â¼Ì³Ð·½Ê½Ò²¸÷²»Ïàͬ¡£´Ó×î¼òµ¥µÄ
¸´ÓÿªÊ¼¡£
1¡¢¹¹Ô캯ÊýдÀ࣬ͨ¹ý·½·¨µ÷Óø´ÖƸ¸ÀàÊôÐÔ¸ø×ÓÀà
ʵÏּ̳Ð
ÕâÀ︸À࣬×ÓÀà¶¼Óù¹Ô캯Êý·½Ê½Ð´£¬²»ÓÃÔÐÍ¡£×ÓÀàµ÷Óø¸ÀຯÊýÀ´¸´ÖƸ¸ÀàµÄÊôÐÔ¡£
/**
* ¸¸ÀàPolygon:¶à±ßÐÎ
* @param {Object} sides
*/
function Polygon(sides) {
this.sides = sides;
this.setSides = function(s) {this.sides=s;}
}
/**
* ×ÓÀàTriangle:Èý½ÇÐÎ
*/
function Triangle() {
this.tempfun = Polygon;//¸¸ÀàÒýÓø³Öµ¸ø×ÓÀàµÄÒ»¸öÊôÐÔtempfun
this.tempfun(3);//µ÷ÓÃ
delete this.tempfun;//ɾ³ý¸ÃÊôÐÔ
this.getArea = function(){};
}
//new¸ö¶ÔÏó
var tri = new Triangle();
console.log(tri.sides);//¼Ì³ÐµÄÊôÐÔ
console.log(tri.setSides);//¼Ì³ÐµÄ·½·¨
console.log(tri.getArea);//×ÔÓеķ½·¨
//ȱµãÊǶÔÓÚTriangleµÄʵÀý¶ÔÏóÓÃinstanceofΪ¸¸ÀàPolygonʱÊÇfalse
console.log(tri instanceof Triangle);//true
console.log(tri instanceof Polygon);//false
ÒòΪjs¾ßÃûº¯ÊýÓÐËÄÖÖµ÷Ó÷½Ê½
£¬×ÓÀ໹¿ÉÒÔÓÐÒÔϵĶàÖÖʵÏÖ·½Ê½¡£Ö»ÊÇÔÚ×ÓÀàÖе÷Óø¸Àà·½·¨²»Í¬¶øÒÑ¡£
function Triangle() {
Polygon.call(this,3);//call·½Ê½µ÷Óø¸Àà
this.getArea = function(){};
}
function Triangle() {
Polygon.apply(this,[3]);//apply·½Ê½µ÷Óø¸Àà
this.getArea = function(){};
}
function Triangle() {
var temp = new Polygon(3);//new·½Ê½µ÷Óø¸Àà
for(atr in temp)//È«²¿¸´ÖƸø×ÓÀà
this[atr] = temp[atr];
this.getArea = function(){};
}
ÕâÖÖ·½Ê½µÄȱµãÊÇ×ÓÀàµÄʵÀý¶ÔÏóÓÃinstanceof¼ì²é¸¸Ààʱ×ÜÊÇfalse¡£ÕâÓëjavaÖм̳Ð"is a "µÄ¹ØÏµÊÇÎ¥±³µÄ¡£
Ïà¹ØÎĵµ£º
phpÖеÄevalºÍJavaScriptÖеÄevalÇø±ð£º
Definition and Usage
¶¨ÒåºÍÓ÷¨
The eval() function evaluates a
string as PHP code.
eval()º¯ÊýµÄ×÷ÓÃÊÇ£º·µ»ØÓëPHP´úÂëÏà¶ÔÓ¦µÄ×Ö·û´®¡£
The string
must be valid PHP code and must end with semicolon.
Õâ¸ö×Ö·û´®±ØÐëÊÇÓÐЧµÄPHP´úÂ룬
²¢ÇÒ±ØÐëÒԷֺŽáÊø¡ ......
Identifier Resolution Performance ±êʶ·ûʶ±ðÐÔÄÜ
Identifier resolution isn't free, as in fact no computer operation really is without some sort of performance overhead. The deeper into the execution context's scope chain an identifier exists, the slower it is to access for ......
Dynamic Scopes ¶¯Ì¬×÷ÓÃÓò
Both the with statement and the catch clause of a try-catch statement, as well as a function containing eval_r(), are all considered to be dynamic scopes. A dynamic scope is one that exists only through execution of code and therefore cannot be det ......
Nested Members ǶÌ׳ÉÔ±
Since object members may contain other members, it's not uncommon to see patterns such as window.location.href in JavaScript code. These nested members cause the JavaScript engine to go through the object member resolution process each time a dot is ......