Skip to content

Instantly share code, notes, and snippets.

@rkaw92
Created May 11, 2017 22:21
Show Gist options
  • Save rkaw92/0207f287fe8fb0a795c744dd356a968c to your computer and use it in GitHub Desktop.
Save rkaw92/0207f287fe8fb0a795c744dd356a968c to your computer and use it in GitHub Desktop.
Prototypal inheritance
function BucketCollector() {
}
BucketCollector.prototype.addToBucket = function addToBucket(item) {
this.items.push(item);
};
BucketCollector.prototype.items = [];
var a = new BucketCollector();
var b = new BucketCollector()
a.addToBucket('thing');
b.addToBucket('otherThing');
console.log('a.items:', a.items);
console.log('b.items:', b.items);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment