写了一个js对象var md = {
}请看图中setout明明是个函数,在执行的时候,却一直报,setout不是函数,求解
你把this打印出来就知道是为什么了。
this
我赌五毛这个this是window
window
你引用方法的地方没有获取到md对象.
xxx.bind(this);
var _this = this || md;
你在updateHash里面写了this.setout(); 吧?this.hashto=setTimeout(this.updateHash.bind(this),1000)
updateHash
this.setout();
this.hashto=setTimeout(this.updateHash.bind(this),1000)
改成箭头函数应该也可以:
setout:(val)=>{ .... }
全局声明this var self= this; updata:function(e){ self.setout('eee'); ... }
全局声明this
var self= this;
updata:function(e){ self.setout('eee'); ... }
你把
this
打印出来就知道是为什么了。我赌五毛这个
this
是window