`

javascript 'this' , with prototype, closure

 
阅读更多

just give an example

function Controller(){
}

Controller.prototype=(function(){
var p1=function(){
console.log(this);
};

var p2=function(){
console.log("in p2");
};
return {
//create an object as the prototype, supposed it is named as "p1"
fun1:function(){
console.log(this);
},
fun2:p1,
fun3:function(){
p1();
}
}
})();

var c=new Controller();
c.fun1();//this represents the prototype object p1
c.fun2();//this represents the prototype object p1
c.fun3();//this represents the window
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics