手写继承 和 new的过程

2021-02-03  本文已影响0人  Volcaner
var School = function() {
  this.name = "xxx";
  this.schoolmaster = "school master";
  this.open = function() {
    console.log('School Open: ', this.name);
  };
}
School.prototype.create_time = "2020.08.08";
var College = function() {
  School.call(this);
  this.college_name = "xxx KKK college";
  this.college_enroll = function() {
    console.log(this.college_name + ' 招生!');
  };
}
// new
var college_1 = new College();

// 手动new
var college_2 = {};
college_2._proto_ = College.prototype;  // Object.setPrototypeOf(college_2, College.prototype);
College.call(college_2);
上一篇 下一篇

猜你喜欢

热点阅读