《悟透javascript》-3.1

来源:互联网 发布:程序员的数学pdf 编辑:程序博客网 时间:2024/05/28 17:07

闭包;
当碰到对象之间复杂的循环引用时,垃圾回收的判断逻辑非常复杂。故有时才用原型模型;

// 定义构造函数function Person(name){    this.name=name;}// 方法定义到构造函数的原型上Person.prototype.SayHello=function(){    console.log("hello,I'm "+this.name)};// 子类构造函数function Employee(name,salary){    Person.call(this,name);//调用上层构造函数    this.salary=salary;}Employee.prototype=new Person();Employee.prototype.ShowMeTheMoney=function(){    console.log(this.name+" $ "+this.salary)}var BillGates=new Person("Bill Gates");BillGates.SayHello();var SteveJobs=new Employee("Steve Jobs",1234);SteveJobs.SayHello();SteveJobs.ShowMeTheMoney();
原创粉丝点击