javascript - How can I keep the context of 'this' in jquery -


मेरे पास ऐसा कुछ है:

  var कुछ = कार्य () {this.render = फ़ंक्शन () {}; $ (विंडो)। Reset (फ़ंक्शन () {this.render ();}); }  

परेशानी यह है कि गुमनाम समारोह के अंदर 'यह' विंडो ऑब्जेक्ट को संदर्भित करता है। मुझे पता है कि मैं ऐसा कुछ कर सकता हूं:

  var कुछ = कार्य () {this.render = function () {}; Var temp यह = यह; $ (विंडो)। Reset (फ़ंक्शन () {tempThis.render ();}); }  

लेकिन क्या कोई बेहतर तरीका है? यह बहुत ही खूबसूरत नहीं दिखता है।

आपको जो समाधान मिला है वह है जो कि अधिकांश लोगों का इस्तेमाल होता है। आम सम्मेलन आपके tempThis चर "कि।" कॉल करने के लिए है

  var कुछ = समारोह () {this.render = function () {}; Var = यह; $ (विंडो)। Reset (फ़ंक्शन () {that.render ();}); };  

Comments

Popular posts from this blog

SQL/PHP: Table design question -

NHibernate Passing Session to the Repository -

c# - XMLDocument.Validate Error: System.InvalidOperationException : The XmlSchemaSet on the document is either null or has no schemas in it -