avaScript设计模式 中文清晰扫描版PDF 百度网盘下载:http://pan.baidu.com/s/1mg8a9rM
------------------------------------------分割线------------------------------------------
FTP地址:ftp://ftp1.linuxidc.com
用户名:ftp1.linuxidc.com
在 2015年LinuxIDC.com\9月\JavaScript设计模式 中文清晰扫描版PDF
下载方法见 http://www.linuxidc.com/Linux/2013-10/91140.htm
------------------------------------------分割线------------------------------------------
本文永久更新链接地址:http://www.linuxidc.com/Linux/2015-09/122725.htm
第四章 继承
类式继承
function Person(name){
this.name = name;
}
Person.prototype.getName = function() {
return this.name;
}
var reader = new Person('John Smith');
reader.getName();
function Author(name, books){
Person.call(this, name); //Call the superclass's constructor in the scope of this.
this.books = books; //Add an attribute to Author.
}
Author.prototype = new Person(); //Set up the prototype chain.
Author.prototype.constructor = Author; //Set the constructor attribute to Author.
Person.prototype.getBooks = function() { //Add a method to Author.
return this.books;
}
var author = new Author('Ross Harmes', ['JavaScript Design Patterns']);
author.getName();
author.getBooks();
建议下面写法
function Contacts()
原型式继承
欢迎光临 firemail (http://firemail.wang:8088/) | Powered by Discuz! X3 |