Created
October 19, 2012 19:04
-
-
Save pguillory/3920044 to your computer and use it in GitHub Desktop.
Classify vs Closures
This file contains hidden or 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 hidden or 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