对象方法链化

come from javascriptcookbook

 1 function book (title, author) {
 2     this.getTitle = function () {
 3         return 'title: " + title;
 4     }
 5 
 6     this.replaceTitle = function (newTitle) {
 7         var oldTitle = title;
 8         title = newTitle;
 9     }
10 }
1 function newbook (
2     book.apply (this, arguments)
3 
4     this.replaceTitle = function (newTitle) {
5         this.replaceTitle(newAuthor)
6         return this;  //支持方法链化所必需的
7     }
8 }

使用call()将两个对象连接起来。如果想在两个对象之间传递参数列表,则使用apply()。

原文地址:https://www.cnblogs.com/lancelotseven/p/8043520.html