Skip to content

Instantly share code, notes, and snippets.

@pose
Last active December 26, 2015 20:19
Show Gist options
  • Save pose/7207762 to your computer and use it in GitHub Desktop.
Save pose/7207762 to your computer and use it in GitHub Desktop.
Pseudo-inheritance in JS
angular.module('otherModule', ['myModule'])
.factory('consumer', function (myClass) {
var instance1 = myClass(),
instance2 = myClass(),
instance3 = myClass();
}})
angular.module('otherModule', ['myModule'])
.factory('consumer', function (mySingleton) {
var instance = mySingleton;
}})
angular.module('myModule', [])
.factory('myClass', function () {
function myClass() {
var d = {};
d.myMethod = function (x) {
return x + 5;
}
return d;
}
return myClass;
});
angular.module('myModule', [])
.factory('mySingleton', function () {
function myClass() {
var d = {};
d.myMethod = function (x) {
return x + 5;
}
return d;
}
return myClass();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment