Skip to content

Instantly share code, notes, and snippets.

@diegograssato
Forked from goranprijic/1-traits.js
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diegograssato/38cde959c9bf978d258c to your computer and use it in GitHub Desktop.
Save diegograssato/38cde959c9bf978d258c to your computer and use it in GitHub Desktop.
angular.module('myApp')
.factory('Traits', function() {
return {
apply: function (_class, _trait) {
_.each(_trait, function (method, name) {
_class.prototype[name] = method;
});
}
}
});
angular.module('myApp')
.factory('MyTrait', function() {
return {
someMethod: function (param) {
//
},
anotherMethod: function (param) {
//
}
}
});
angular.module('myApp')
.factory('MyResource', function($resource, Traits, MyTrait) {
var resource = $resource();
Traits.apply(resource, MyTrait);
return resource;
});

Simple way how to implement Traits in AngularJS

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