Skip to content

Instantly share code, notes, and snippets.

@petsel
Last active December 16, 2015 05:29
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 petsel/5385163 to your computer and use it in GitHub Desktop.
Save petsel/5385163 to your computer and use it in GitHub Desktop.
Trait example for "Enumerable" that implements only two methods [first] and [last]
/**
* see also / derived from:
* [https://github.com/petsel/composable/blob/master/src/components/Enumerable/Enumerable.first-last-item.js]
* [https://github.com/petsel/composable/blob/master/src/composites/Array/Array.first-last.js]
*/
var Enumerable_first_last = (function () {
var
Trait, // the "Enumerable_first_last" Trait Module.
first = function () {
return this[0];
},
last = function () {
return this[this.length - 1];
}
;
Trait = function () {
/**
* implementing the "Enumerable_first_last" Trait Module.
*/
this.first = first;
this.last = last;
};
return Trait;
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment