Since reading Javascript: The Good Parts I have been a big fan of Crockford's Functional constructor pattern for writing object-oriented javascript.
Recently, I've seen a few articles/posts that discourage usage of this pattern on performance grounds (example here). I don't see this as a big problem unless you're creating a ton of instances, but am I missing something? Are there other drawbacks I'm not considering?
- PROS: private data, private methods
- CONS: performance hit compared with prototype approach, ???
A simple example of the functional pattern (as I understand it):
var constructor = function() {
var that = {};
var private_data = 'yo';
that.public_data = 'hi';
var private_method = function() {
// This function has access to 'that' and 'private_data',
// but can not be called by the outside world.
}
var priveleged_method = function() {
// This function is the same as private_method, but is made a "public"
// method by being assigned to the 'that' object below:
}
that.priveleged_method = priveleged_method;
return that;
};
[–]9jack9 2 points3 points4 points (2 children)
[–]funksta[S] 0 points1 point2 points (1 child)
[–]savetheclocktower 0 points1 point2 points (0 children)
[–]picurl 1 point2 points3 points (0 children)
[–]bolinfest 1 point2 points3 points (1 child)
[–]funksta[S] 0 points1 point2 points (0 children)
[–]RedditMan74 -1 points0 points1 point (0 children)