function employee(name, job, born) {
this.name = name;
this.job = job;
this.born = born;
}

function house() //这个是新的类
{
this.addr = "beijing";
//var family=fuction(); //这又是一个类 里面可能还有wife,chilren等类
}

employee.prototype.salary = 50000; //基本工资
employee.prototype.house = new house();

var bob = new employee("Bill Gates", "Engineer", 1985);
var bill = new employee("Bill Gates", "Engineer", 1985);

bob.salary = 10000;
bill.salary = 20000;

console.log(bill.salary);
console.log(bob.salary);
console.log(bill.house.addr); // "beijing"-->就是要实现这个效果

总结:函数属性赋值=对象。这样调用函数属性就可以调用到其它对象上的属性和方法,从而达到效果。

05-11 20:43