Ian Bicking: the old part of his blog

Re: Prototype and object prototype comment 000

applay() not only simply replace 'this' with the assigned object,it also provides the executing enviroment for the function which is applied.

var obj1={
value:1,
foo:function(){
alert(this.value);

System Message: WARNING/2 (<string>, line 7)

Definition list ends without a blank line; unexpected unindent.

}

System Message: WARNING/2 (<string>, line 8)

Definition list ends without a blank line; unexpected unindent.

}

var obj2={

value:2, setFoo:function(foo){

System Message: ERROR/3 (<string>, line 13)

Unexpected indentation.
this.foo = foo;

System Message: WARNING/2 (<string>, line 14)

Block quote ends without a blank line; unexpected unindent.

}

System Message: WARNING/2 (<string>, line 15)

Definition list ends without a blank line; unexpected unindent.

}

setFoo(foo){
this.foo = foo;

System Message: WARNING/2 (<string>, line 19)

Definition list ends without a blank line; unexpected unindent.

}

setFoo.apply(obj2,[obj1.foo]) in fact equals obj2.setFoo(obj1.foo)

obj2.setFoo(obj1.foo) means setFoo will be evaluated in the obj2 scope while the expression obj1.foo = obj2.foo will be evaluted in global scope.

Comment on Prototype and object prototype comment 000
by wl_tony