Skip to content

Instantly share code, notes, and snippets.

@doup
Created July 25, 2010 20:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save doup/489840 to your computer and use it in GitHub Desktop.
Save doup/489840 to your computer and use it in GitHub Desktop.
var Base = {
_ops: {},
_privateFnc: function () {},
abstract: function () {},
init: function (ops) {
this._ops = ops || {};
// INIT
}
};
var Thing = (function () {
var ThingBase = Object.create(Base);
ThingBase = {
abstract: function() {
return this._ops;
}
};
return function (ops) {
var instance = Object.create(ThingBase);
instance.init(ops);
return instance;
};
})();
var thingA = Thing(),
thingB = Thing({foo:'bar'});
@doup
Copy link
Author

doup commented Dec 9, 2010

Object instantiation pattern JS way. Does it make sense? More ideas without using "new" operator?

@polotek
Copy link

polotek commented Dec 9, 2010

Re-arranged things a bit to cut down on object creation and get rid of the unnecessary closure. Of course I didn't test that at all :)

https://gist.github.com/734781

@doup
Copy link
Author

doup commented Dec 9, 2010

@xk oooops, true. I didn't notice... -_-

@xk @polotek, so basically you both get rid of the closure (actually makes sense) and have taken a similar approach. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment