私の問題の例:
/**
* @constructor
*/
function Marker(opts) {
opts = opts || {};
this.text = opts.text || 'Hello!';
this.node = null;
this.init();
};
Marker.prototype = {
init: function() {
this.node = document.createElement('div');
this.node.innerHTML = this.text;
document.body.appendChild(this.node);
},
destroy: function() {
if ( this.node && this.node.parentNode )
this.node.parentNode.removeChild(this.node);
for (var i in this)
if ( this.hasOwnProperty(i) )
delete this[i];
// this.constructor = null; // :-(
// this = null; // :-(
// H O W ?
}
};
var first = new Marker({ text: 'first' });
alert( first instanceof Marker );
first.destroy();
alert( first instanceof Marker ); // want false
2 番目のメッセージ ボックスに false を表示するには、どのようにメソッドを更新すればよい.destroy()
ですか? ソリューションは、protoを使用せずにクロスブラウジングする必要があります。