function Ff(){}
//undefined
Ff.prototype={a:"ss"}
//Object {a: "ss"}
var f1= new Ff()
//undefined
Ff.prototype.constructor
//Object() { [native code] }
f1.constructor
//Object() { [native code] }

重写prototype,导致实例的constructor发生改变。

var extend = function(protoProps, staticProps) {//{defaults:{name:,price}}
var parent = this;
var child; // The constructor function for the new subclass is either defined by you
// (the "constructor" property in your `extend` definition), or defaulted
// by us to simply call the parent's constructor.
if (protoProps && _.has(protoProps, 'constructor')) {
child = protoProps.constructor;
} else {
child = function(){ return parent.apply(this, arguments); };
} // Add static properties to the constructor function, if supplied.
_.extend(child, parent, staticProps); // Set the prototype chain to inherit from `parent`, without calling
// `parent`'s constructor function.
var Surrogate = function(){ this.constructor = child; };
Surrogate.prototype = parent.prototype;
child.prototype = new Surrogate; // Add prototype properties (instance properties) to the subclass,
// if supplied.
if (protoProps) _.extend(child.prototype, protoProps); // Set a convenience property in case the parent's prototype is needed
// later.
child.__super__ = parent.prototype; return child;
};

继承之重写prototype的更多相关文章

  1. 原型链继承中的prototype、__proto__和constructor的关系

    前不久写了有关原型链中prototype.__proto__和constructor的关系的理解,这篇文章说说在原型链继承中的prototype.__proto__和constructor的关系. 通 ...

  2. 【转载】 C++多继承中重写不同基类中相同原型的虚函数

    本篇随笔为转载,原文地址:C++多继承中重写不同基类中相同原型的虚函数. 在C++多继承体系当中,在派生类中可以重写不同基类中的虚函数.下面就是一个例子: class CBaseA { public: ...

  3. Php面向对象 – 继承和重写

    Php面向对象 – 继承和重写 承受: php于,通过类.使用特殊的经营宗旨. 通过定义类,采用extends来表示当前的类对象继承该类的对象. 样例: class C { public  $p_c  ...

  4. 创建线程时如果既传入了runnable对象,又继承thread重写了run方法,会执行的哪里的代码

    1 使用线程的方式,继承thread类,重写run方法 new Thread() { @Override public void run() { System.out.println("我是 ...

  5. Django admin 继承user表后密码为明文,继承UserAdmin,重写其方法

    Django用户继承AbstractUser后密码为明文 其实本不应该有这个问题,却花了我很久的时间,因为还是初学阶段. 造成这个原因是因为在admin注册的生活没有指定Admin 在app的admi ...

  6. C#和Java的类、继承、重写与多态

    面向对象的三大特性是封装.继承.多态,C#和Java都是面向对象的语言所以他们的类.继承.重写与多态有很多共同点,但是实现上也存在一定的区别.其中Java中其实没有虚函数的概念,也可以认为Java的函 ...

  7. Java多态机制和继承中重写重载

    关于Java中多态机制 http://www.cnblogs.com/chenssy/p/3372798.html 这篇博文讲的很透彻 大体意思是 多态定义: 多态就是指程序中定义的引用变量所指向的具 ...

  8. 重写prototype原型后哪些东西改变了

    参考<JavaScript高级教程>实例看: 1.重写原型对象后,首先原型对象的constructor属性值(constructor的指向)会发生改变. function Person() ...

  9. 浅析 Java 中的继承和重写

    浅析 Java 中的继承和重写 Java 中的构造方法不能被继承. Java 中 static 修饰的方法可以被继承,但不能被子类重写. Java 中 final 修饰方法不允许被子类重写,但是可以被 ...

随机推荐

  1. 小型机与pc服务器区别

    按CPU的类型来区分,小型机是基于RISC(精简指令集)架构的专用服务器,而服务器是基于CISC(复杂指令集)架构的PC服务器.小型机相对于普通服务器来说,一直有不可比拟的优势.(1)如必能稳定,它具 ...

  2. python3 序列

    python中有很多内置序列 列表 元组 字符串 python中容器的概念 列表 元组 字符串 字典 集合 是可以改变的,元组不可改变 几乎可以在所有情况下用列表代替元组,只有一种情况下,是不可以的, ...

  3. IOS8刷机之后

    用的4s,明显感觉卡- =BUG也非常多,点击设置都闪退..有些应用打不开. 不建议非开发人员尝试. 眼下发现的bug有:同一时候关闭多个应用会造成应用无法关闭. 常常重新启动.耗电没留意.

  4. 关于右移和除法的关系 , ADC采集电量 ,ADC采集MIC(麦克风)

    //////////////////////////////////////////////////////////////////////////////////////////////////// ...

  5. [Recompose] Add Local State with Redux-like Reducers using Recompose

    Learn how to use the 'withReducer' higher order component using the alternative reducer form. If you ...

  6. 仿凤凰时时彩代购平台源代码[ASP+MSSQL]完整下载

    源代码简单介绍 : 适用范围:  时时彩源代码,时时彩程序,开奖平台源代码,投注平台源代码,仿凤凰时时彩源代码 执行环境:  ASP+MSSQL 其它说明:仿凤凰时时彩代购平台源代码.网上售价8000 ...

  7. Linux系统下的单调时间函数

    欢迎转载,转载请注明出处:http://forever.blog.chinaunix.net 一.编写linux下应用程序的时候,有时候会用到高精度相对时间的概念,比如间隔100ms.那么应该使用哪个 ...

  8. php随机字符串

    <?php class RandChar{ function getRandChar($length){ $str = null; $strPol = "ABCDEFGHIJKLMNO ...

  9. Drupal 7 模块开发 建立模块帮助信息(hook_help)

    建立模块请參考 <Drupal 7 模块开发 建立> 假设你要支持中文,文件格式必须保存为 UTF-8.NO BOM ------------------------------ hook ...

  10. [React] Modify file structure

    In React app, you might create lots of components. We can use index.js to do both 'import' & 'ex ...