Skip to content

Instantly share code, notes, and snippets.

@ety001
Last active August 29, 2015 14:02
Show Gist options
  • Save ety001/8c0d19ae0405b01d589d to your computer and use it in GitHub Desktop.
Save ety001/8c0d19ae0405b01d589d to your computer and use it in GitHub Desktop.
JS apply call
var Person = function(name,age){
this.name = name;
this.age = age;
}
var Print = function(){
this.functionName = 'Print';
this.show = function(){
var msg = [];
for(var key in this){
if(typeof(this[key])!='function'){
msg.push([key,':',this[key]].join(''));
}
}
console.log(msg.join(' '));
}
}
var Student2 = function(name,age,school,grade){
Person.apply(this,arguments);
Print.apply(this,arguments);
console.log(this);
this.school = school;
this.grade = grade;
}
var s = new Student2('Jim',22,'Harvard',2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment