我有可以简化这样的类:这是怎么来的,_这是否引用了一个对象的不同实例?
Captcha = function(el) {
this.el = $(el);
_this = this;
captchas.push(this);
};
Captcha.prototype.render = function(grecaptcha){
console.log(this.el.dom[0]);
console.log(_this.el.dom[0])
};
类与传入作为EL两个不同的DOM元素intantiated两次。
渲染在全局回调函数运行时运行。
captchas = [];
//We need this for captchas.
window.CaptchaCallback = function(){
app.captchas.forEach(function(capt){
capt.grecaptcha = grecaptcha;
capt.render();
});
};
出于某种原因,this.el.dom[0]
引用了两种不同的元素,但_this.el.dom[0]
总是引用类,为什么最后一个实例?
你想做什么?你打算让'_this'变量起作用吗? – Pointy