Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Classify vs Closures
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;
}
});
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