function F(){ this.pro=function(){ //doSomething }; function f(){ //pro(); //error,object pro undefined } }
函数 f 想调用F的方法pro以产生某些行为,但实际上这时的pro是属于对象F的一个属性(方法),必须使用F对象的引用才能正确使用这个方法。如果想直接像上面那样调用而不使用对象F的引用来调用,可以这样定义pro:
this.pro=function pro(){
//doSomething
}
另外,alert( typeof(new F().pro) )显示的是function