मैं एक कोलाहल वस्तु के साथ मेरी समस्या का एक सरल उदाहरण दिया:जावास्क्रिप्ट ऑब्जेक्ट को कैसे विस्तारित किया जाए?
function babel(){
this.english = {
hello: function() { alert('hello'); },
goodbye: function() { alert('goodbye'); }
teeshirt: function() { alert('T-shirt'); }
}
}
अब, मैं चाहता हूँ इस वस्तु का विस्तार:
babel.prototype.french = {
bonjour: function() { alert('bonjour'); },
aurevoir: function() { alert('au revoir'); }
}
लेकिन क्या होगा अगर मैंने पहले परिभाषित एक मौजूदा समारोह उपयोग करने की आवश्यकता ? यह
var say = new babel();
(function (_this) {
babel.prototype.french = {
bonjour: function() { alert('bonjour'); },
aurevoir: function() { alert('aurevoir'); },
hello: function() { _this.english.hello(); }
}
})(say);
लेकिन इस मामले में, मैं हमेशा कहते हैं वस्तु के संदर्भ का उपयोग करेगा, नहीं है:
babel.prototype.french = {
bonjour: function() { alert('bonjour'); },
aurevoir: function() { alert('aurevoir'); },
teeshirt: function() { this.english.teeshirt(); }
}
क्या मैं कर सकता है?
[जावास्क्रिप्ट ऑब्जेक्ट से एक्सेस अभिभावक के माता-पिता] के संभावित डुप्लिकेट (http://stackoverflow.com/questions/183702/access-parents-parent-from-javascript-object) – JJJ
क्या आप चाहते हैं 'var b = नया बेबेल(); बी.फ्रेंच.टेशर्ट(); 'टी-शर्ट "को सतर्क करने के लिए? या कुछ अन्य व्यवहार? –
हां, यह वह व्यवहार है जिसे मैं पसंद करूंगा, लेकिन इसके अलावा, मैं अपने ऑब्जेक्ट के संदर्भ का उपयोग करना चाहता हूं। – Natim