JS 函数内子类调用和链式调用语法

子类方法调用

function person(name) {
  this.name = name
}

function Student(name, className) {
  this.className = className
  person.call(this, name)
}

var bosn = new Student('bosn', 'Grade2')
console.log('bosn', bosn);
//Student { className: 'Grade2', name: 'bosn' }
person.prototype.init = function() {
  console.log('person init');
}
Student.prototype.init = function() {
  console.log('Student init');
  person.prototype.init.apply(this, arguments)
  return this
}
var soh = new Student('soh', 'grade3')
console.log('soh', soh.init());
//Student init
//person init
//soh Student { className: 'grade3', name: 'soh' }

链式调用 

function classManager() {}

classManager.prototype.addClass = function(str) {
  console.log(str + ' added');
  return this
}

var manager = new classManager()
manager.addClass('one').addClass('two').addClass('threee')
//one added
//two added
//threee added