当前位置: 首页 > 图文教程 > 网络编程 > Javascript > JS 继承实例分析

Javascript
仿51JOB的地区选择效果(可选择多个地区)
Javascript打印网页部分内容的脚本
Ext面向对象开发实践(续)
js的闭包的一个示例说明
javascript 字符串连接的性能问题(多浏览器)
JavaScript脚本性能优化注意事项
js电信网通双线自动选择技巧
js DIV滚动条随机位置的设置技巧
Javascript日期对象的dateAdd与dateDiff方法
小试JavaScript多线程
jquery $.ajax入门应用一
JS 俄罗斯方块完美注释版代码
JavaScript在IE中“意外地调用了方法或属性访问”
设置下载不需要倒计时cookie(倒计时代码)
拖拉表格的JS函数
js刷新框架子页面的七种方法代码
FireFox与IE 下js兼容触发click事件的代码
js利用div背景,做一个竖线的效果。
javascript 贪吃蛇实现代码
JavaScript无提示关闭窗口(兼容IE/Firefox/Chrome)

Javascript 中的 JS 继承实例分析


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 102 ::
收藏到网摘: n/a

主要有三种方法: 1. this.method=Parent; this.method=Parent's constructor 2. Parent.call(this,arg,arg,arg.....);3.Parent.apply(this,arg.arg...) //for Array 还是来点实际的吧...
复制代码 代码如下:

function P(name){
this.name=name;
this.p1=function(){
alert('Parent Constructor');
}
return this;
}
function C(name,id){
//this.method=P;
//this.method(name); //1st method
//P.call(this,name); //2nd method
P.apply(this,new Array(name));//3rd method
this.id=id;
this.dis=function(){
alert(this.name);
}
}
function dis(){
alert(this.name);
}
function t(){
var cc=new C('N','Id');
cc.dis();
cc.p1();
}