📄 4.04 - prototypal inheritance.js
字号:
/* Person Prototype Object. */var Person = { name: 'default name', getName: function() { return this.name; }};var reader = clone(Person);alert(reader.getName()); // This will output 'default name'.reader.name = 'John Smith';alert(reader.getName()); // This will now output 'John Smith'./* Author Prototype Object. */var Author = clone(Person);Author.books = []; // Default value.Author.getBooks = function() { return this.books;}var author = [];author[0] = clone(Author);author[0].name = 'Dustin Diaz';author[0].books = ['JavaScript Design Patterns'];author[1] = clone(Author);author[1].name = 'Ross Harmes';author[1].books = ['JavaScript Design Patterns'];author[1].getName();author[1].getBooks();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -