Skip to content

Instantly share code, notes, and snippets.

@Cfeusier
Created December 14, 2014 05:56
Show Gist options
  • Select an option

  • Save Cfeusier/d864116f9ac1f241e6fa to your computer and use it in GitHub Desktop.

Select an option

Save Cfeusier/d864116f9ac1f241e6fa to your computer and use it in GitHub Desktop.
Example of the Functional-Shared 'Class' Pattern in JavaScript
var Example = function() {
var example = {};
example.extraProp1 = "Example Property Value";
_.extend(example, exampleMethods); // requires _ library or implement your own extend function
return example;
};
var exampleMethods = {
exampleGet: function() {
return this.extraProp1;
},
exampleSet: function(value) {
this.extraProp1 = value;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment