1.我们写的变量 ,函数默认域都是window对象,也就是this(指向调用该方法的对象).如在firebug 控制台中运行以下程序,会在 firebug的Dom标签中的window頙有s2属性.在这个DOM标签中,子节点可以访问上层父节点的变量 ,反之不行.
var tip=function(){var s1="bgg1";this.s2="bgg2";}
alert(new tip().s2); //anonymouse object 's property
tip()
alert(s2); //windows's property
var s2=new (new Function("test","alert(test);this.name=test"))("bgg");
var s3=(new Function("test","alert(test);this.name=test"))("bgg");
alert(s2);
alert(s3);
alert(s2.name);
alert(s3.name);
2.js 几个函数的函数
Function也是一个类,对象object就是一个associative array。 当你定义了一个新的函数, 你实际上声明了一个新的类, 而这个函数本身就相当于类的构造函数。其中函数中的this指向函数调用者;如
var s2=new (new Function("test","alert(test);this.name=test"))("bgg");
var s2=new (new Function("test","alert(test);this.name=test"))("bgg");
constructor:对创建对象的函数的引用
call 方法 调用一个对象的一个方法,以另一个对象替换当前对象。
apply和call两者在作用上是相同的,但两者在参数上有区别的。apply将多个参数组合成为一个数组传入
arguments:函数的参数
caller: 返回一个对函数的引用,该函数调用了当前函数。
callee: 返回正被执行的 Function 对象,也就是所指定的 Function 对象的正文。
prototype:prototype本身也是一个对象,解释器在没有在当前对象找到要找的属性后,就会去检查这个对象的prototyp.读操作会读取在obj自己和prototype 链上发现的第一个同名属性值 .写操作会为obj对象本身创建一个同名属性
html中的函数:会转成一个函数内容,如οnclick="alert(1)",解释器会生成 element.οnclick=function(){alert(1);}
参考:
1.https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Functions
2.http://www.iteye.com/topic/53537
3.http://www.iteye.com/topic/119815