Skip to content

Instantly share code, notes, and snippets.

@d8ta
Last active August 29, 2015 14:10
Show Gist options
  • Save d8ta/549f100b7a89c24126cb to your computer and use it in GitHub Desktop.
Save d8ta/549f100b7a89c24126cb to your computer and use it in GitHub Desktop.
Prototyping extension
//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