Skip to content

Instantly share code, notes, and snippets.

@quackingduck
Last active December 20, 2015 02:29
Show Gist options
  • Save quackingduck/6056491 to your computer and use it in GitHub Desktop.
Save quackingduck/6056491 to your computer and use it in GitHub Desktop.
javascript madness __proto__ and prototype and class
// OBJECT PROGRAMMING
avi = {
walk: function() { console.log(this.name + ' is walking') },
name: 'Avi'
}
avi.walk()
avi.lastName = 'Kaufman'
// PROTOTYPE PROGRAMMING
anotherAvi = {}
anotherAvi.__proto__ = avi
console.log(anotherAvi.name)
// CLASS BASED
function Person(name) {
this.name = name
}
Person.prototype.walk = function() { console.log(this.name + ' is walking') }
console.log(new Person('bill'))
// confused? http://dmitry.baranovskiy.com/post/objects-in-javascript-part-ii
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment