function person(){
this.name="abc";
}
person.prototype={
showName:function(){
console.log(this.name);
},
info:{
showName:function(){
var _this=this;
console.log(_this.name);
}
}
}
代码里面两处_this指向不同,怎么让_this都指向person内部,还有在写插件时有什么办法只写一次_this,然后全局都可以调用,注意!!千万不要提供在person外面设置全局变量_this这种办法!!!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
一般用 变量 that 在person 将this 接收一下
个人觉得没办法实现。你可以让他们这样调用啊:
这就解决了 this 指向的问题了
个人觉得,如果方法重名,还不如在方法内部做一下判断。
否则的话就像 @灰色v碰触 说的那样:
在外面指定调用者。
当然就我个人而言,并不喜欢使用原型方式来书写。