1. 程式人生 > >鏈式呼叫原理

鏈式呼叫原理

 

var testFn = function () {}
testFn.prototype = {
  fn1: function () {
    console.log(this);
    console.log('fn1');
    return this;
  },
  fn2: function () {
    console.log(this);
    console.log('fn2');
    return this;
  },
  fn3: function () {
    console.log(this);
    console.log('fn3');
    return this;
  }
};
var testFn = new testFn();
testFn.fn1().fn2().fn3();

鏈式呼叫本質是: 例項化的函式呼叫原型物件上的方法;