美文网首页
手写继承 和 new的过程

手写继承 和 new的过程

作者: Volcaner | 来源:发表于2021-02-03 11:46 被阅读0次
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);

相关文章

  • 手写继承 和 new的过程

  • (一)new()& 构造函数

    方法 new方法 (之前学习) 类名 对象名称 =new 类名() 类继承new() 和接口继承new() 因为继...

  • js种new的过程和js继承的记录

    new操作符的工作原理是什么?它是怎么样改变构造函数的返回值和this指向的? 我们都知道new运算符是用来实例化...

  • JS继承

    拷贝继承: 通用型的 有new或无new的时候都可以类式继承: new构造函数原型继承: 无new的对象 ...

  • 贪吃蛇

    先看继承和冒充;# function a(){};b.prototye= new a()'b 继承a,是可以把a的...

  • 手写new

  • 如何手写一个new

    和人交流时发现,现在面试可能会问到如何手写一个new,也就是如何自己手写方法实现new()功能 ,觉得自己从没想过...

  • 原生JS继承相关概念

    原型链继承 借用构造函数(经典继承) 缺点 :每次new (实例化)都会重现创建一次 组合继承 (结合原型链继承和...

  • 面试秘籍之手写系列

    一、手写call函数 二、手写bind函数 三、手写实现new功能的函数 四、手写reduce函数 五、手写防抖函...

  • JS继承的方法

    继承的作用 继承通常的作用是用过使用继承从而得到代码的复用. js中new的作用 举个例子,var a=new H...

网友评论

      本文标题:手写继承 和 new的过程

      本文链接:https://www.haomeiwen.com/subject/yyvptltx.html