Last active
August 29, 2015 14:10
-
-
Save d8ta/549f100b7a89c24126cb to your computer and use it in GitHub Desktop.
Prototyping extension
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//immediate function: it is convention to sign it with an $ if you use jQuery (but we did not use jQuery here??)) | |
$(function () { | |
//constructor function | |
function Person(name) { | |
console.log('constructor::Person'); | |
console.log(this); | |
this.name = name; | |
} | |
Person.prototype.sayHello = function() { | |
console.log('hello: my name is: ' + this.name); | |
}; | |
Person.prototype.walk = function() { | |
console.log('walk'); | |
}; | |
function Student(name, id) { | |
console.log('constructor::Student'); | |
//Person.call(this, name); | |
Person.apply(this, arguments); | |
this.id = id; | |
} | |
//Student.prototype = new Person(); | |
Student.prototype = Object.create(Person.prototype); | |
Student.constructor = Student; | |
Student.prototype.dance = function() { | |
console.log('dance'); | |
}; | |
Student.prototype.walk = function() { | |
console.log('walk!'); | |
}; | |
var franzi = new Person('franzi'); | |
var hansi = new Student('hansi', '123'); | |
debugger; | |
/*var prototypeObject = { | |
a: 'a', | |
b: 'b' | |
}; | |
var a = prototypeObject; | |
var constructorFunctionA = prototypeObject; | |
//constructorFunctionA = { | |
//}; | |
constructorFunctionA.testA = 'testA'; | |
console.log(a.testA);*/ | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment