分享js寄生组合模式继承
2024-08-26 23:32:55
function person(){ this.name = 'taobao'; this.showMess = function(){ return this.name; } } person.prototype.getVal = function(){ return "hellow word"; } function child(){ person.call(this); this.num = 123; } //提供一个寄生函数 function _initJS(p,c){ var val = Object(p.prototype); val.constructor = c; c.prototype = val; } //调用寄生 _initJS(person,child); //这里记得放在后面定义child child.prototype.showNum = function(){ return this.num } (){ return this.num } var c2 = new child() undefined c2.getVal() "hellow word" c2.showMess() "taobao" c2.showNum() 123
最新文章
- android之二维码扫描的实现
- iframe框架嵌套技巧(全屏,去双滚动条)
- 怎样计算一个整数的位数&;并把每一位上的数字保存下来
- u盘文件系统故障的修复方法
- 【LEETCODE OJ】Binary Tree Postorder Traversal
- 上机实践 - - 一个例子了解C/C++中指针与数组的区别
- linux它SQL声明简明教程---WHERE
- twisted学习笔记 No.2 WebServer
- ios 初体验<;页面切换>;
- JAVAscript学习笔记 js条件语句 第三节 (原创) 参考js使用表 (2017-09-14 15:55)
- 强大的MobaXterm
- 《深入理解Java虚拟机》——Java内存区域与内存溢出异常
- RTMPdump(libRTMP) 源代码分析 9: 接收消息(Message)(接收视音频数据)
- font-size:0的妙用,用于解决inline或者inline-block造成的间隙
- poj2417 bsgs算法非逆元模板,用于求解A^x=B(mod C)的方程
- javascript闭包和this对象
- 深度学习笔记(八)Focal Loss
- 一个canonical标签解决site不在首页的问题
- Linux-(inotify-tools&;rsync)
- unity3d Matrix4x4列为主序