我有可以簡化這樣的類:這是怎麼來的,_這是否引用了一個對象的不同實例?
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