Update contextual Object Literal error property

Discuss other programming languages besides AutoHotkey
User avatar
TLM
Posts: 1608
Joined: 01 Oct 2013, 07:52
Contact:

Update contextual Object Literal error property

24 Nov 2016, 21:45

De-Spaghettifing straight forward jQuery event handlers to Modular Object Literals.
I'm having issues updating errorlevel contextually as seen in the below example.

Code: Select all

var = moduleName {
  error: false,
    init: function() {
      this.cacheDom();
      this.bindEvents();
    },
    cacheDom: function() {
      this.$someElement = $( 'someElement' );
    },
    bindEvents: function() {
      this.$someElement.on( 'someEvent', this.someFunction.bind( this );
    },
    updateErrorLevel: function() {
        // this.error = true;       // << fails
        // this.event.error = true; // << fails        
        moduleName.error = true;    // << works 
    },
    someFunction: function( event ) {
        this.updateErrorLevel.call();
    }
};
 
moduleName.init();
Any ideas if updating using the module name is ok and or how to update the property within context?

Thanks

Return to “Other Programming Languages”

Who is online

Users browsing this forum: No registered users and 18 guests