簡単な JavaScript 継承プロトタイプを作成しましたが、問題が発生しています。正しい宣言を教えてくれる人はいますか?
コード:
var Man = function(params){
this.name = params.name,
this.age = params.age,
this.job = params.job;
}
Man.prototype.work = function(){
return this.name +' is working as a ' + this.job;
}
var Women = function(params){
this.name = params.name,
this.age = params.age,
this.job = params.job;
}
Women.prototype = new Man(); //assigning the prototype
var man1 = new Man({name:'man1',age:'age1',job:'job1'});
console.log(man1.work()); //it works
var woman1 = new Women({name:'woman1',age:'age2',job:'job2'});
console.log(woman1.work()); // it is not.. why?
私が得ているエラー:
TypeError: params is undefined
[Break On This Error]
this.name = params.name,