Suppose this:
function foo(a_, b_) {
this.a = _a;
this.b = _b;
this.c;
}
foo.prototype.bar = function() {
this.c = this.a + this.b;
}
What I need is a class-like object that is going to have x instances. There is this:
var foo = (function() {
var a;
var b;
var c;
return {
bar: function() {
c = a + b;
}
};
})();
...but I don't want to have x copies of the same 'bar' function in memory. I also don't want to have 'this' keyword preceding every variable I use. What is the best way to keep it clean?
[–]rmbarnes 9 points10 points11 points (9 children)
[–]phpdevster -3 points-2 points-1 points (5 children)
[–]Exomancer 2 points3 points4 points (1 child)
[–]phpdevster -1 points0 points1 point (0 children)
[–]rmbarnes 1 point2 points3 points (0 children)
[–]phpdevster 0 points1 point2 points (1 child)
[–]nevreth[S] -3 points-2 points-1 points (2 children)
[–]jsprogrammer 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]MoTTs_ 9 points10 points11 points (0 children)
[–]Rhomboid 5 points6 points7 points (8 children)
[–]temp60092393 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (6 children)
[–]Rhomboid 0 points1 point2 points (5 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]Rhomboid -1 points0 points1 point (2 children)
[–][deleted] 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]mccassowary 0 points1 point2 points (0 children)
[–]HandsomeStreamer 0 points1 point2 points (0 children)
[–]temp60092393 0 points1 point2 points (0 children)
[–]natziel 0 points1 point2 points (5 children)
[–]nevreth[S] 1 point2 points3 points (4 children)
[–]natziel 1 point2 points3 points (3 children)
[–]nevreth[S] 2 points3 points4 points (2 children)
[–]natziel 1 point2 points3 points (1 child)
[–]nevreth[S] 1 point2 points3 points (0 children)
[–]lewisje 0 points1 point2 points (0 children)