Classify vs Closures
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Causes.SomeClass = Causes.classify({ | |
init : function() { | |
this.value = 0; | |
$('#something').on('click', this.handlerFunc.bind(this)); | |
}, | |
handlerFunc : function(event) { | |
event.preventDefault(); | |
this.value += 5; | |
}, | |
// public methods mixed with private ones | |
incrementValue : function() { | |
this.value += 1; | |
}, | |
getValue : function() { | |
return this.value; | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Causes.SomeClass = function() { | |
var value = 0; | |
$('#something').on('click', handlerFunc); | |
function handlerFunc(event) { | |
event.preventDefault(); | |
value += 5; | |
} | |
// public methods are distinct | |
return { | |
incrementValue : function() { | |
value += 1; | |
}, | |
getValue : function() { | |
return value; | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment