javascript 继承
来源:互联网 发布:人工智能中英文介绍 编辑:程序博客网 时间:2024/05/16 19:17
<script>var deepClone = function(source,target){ source = source || {} ; var toStr = Object.prototype.toString , arrStr = '[object array]' ; for(var i in source){ if(source.hasOwnProperty(i)){ var item = source[i] ; if(typeof item === 'object'){ target[i] = (toStr.apply(item).toLowerCase() === arrStr) ? [] : {} ; deepClone(item,target[i]) ; }else{ target[i] = item; } } } return target ;} ;var extend = function(Parent,Child){ Child = Child || function(){} ; if(Parent === undefined) return Child ; //借用父类构造函数 _Child = function(){ Parent.apply(this,arguments) ; Child.apply(this,arguments); } ; //通过深拷贝继承父类原型 _Child.prototype = deepClone(Parent.prototype,_Child.prototype) ; //重置constructor属性 _Child.prototype.constructor = Child ; return _Child;} ;var Parent = function(name){ this.name = name || 'parent' ;} ;Parent.prototype.getName = function(){ return this.name ;} ;Parent.prototype.obj = {a : 1} ;var Child = function(name){ this.childName = name;} ;Child = extend(Parent,Child);var parent = new Parent('myParent') ;var child = new Child('myChild') ;console.log(child.obj.a)</script>
0 0
- javascript继承
- javascript继承
- javascript 继承
- Javascript继承
- Javascript继承
- javascript继承
- Javascript继承
- javascript继承
- JavaScript 继承
- javascript 继承
- JavaScript 继承
- javascript 继承
- javascript 继承
- Javascript继承
- Javascript继承
- Javascript 继承
- JavaScript 继承
- javascript继承
- swap的几种算法
- Android开发者必备的42个链接
- Android json知识汇总
- 多线程下载文件
- Http 416错误解决方案
- javascript 继承
- MongoDB 学习资料
- 多线程断点续传的原理及其简单实现
- Java 系列总结
- 配置RHadoop与运行WordCount例子
- Java设计模式透析之——策略模式
- Java设计模式透析之——适配器模式
- Android使用缓存技术加载多图
- VM安装ubuntu-14.04.1-desktop-amd64遇到的问题