javascript高级属性:私有 和 继承
来源:互联网 发布:网络机房设备 编辑:程序博客网 时间:2024/05/01 21:16
1。私有实现:
实现原则:
·私有属性可以在构造函数中使用var关键字定义
·私有属性只能由特权函数(privileged function)公用访问。特权函数:使用this定义的函数
示例:
2。继承实现
通过脚本实现。 如
3。参考文献:
《 Ajax.基础教程》第5章
实现原则:
·私有属性可以在构造函数中使用var关键字定义
·私有属性只能由特权函数(privileged function)公用访问。特权函数:使用this定义的函数
示例:
function Vehicle(){
var wheelCount = 4; //私有属性
this.getWheelCount = function(){ // 特权函数
return wheelCount;
}
this.setWheelCount = function(count){
wheelCount = count;
}
}
var vehicle = new Vehicle();
vehicle.setWheelCount(5);
var wheel = vehicle.getWheelCount();
alert(wheel);
var wheelCount = 4; //私有属性
this.getWheelCount = function(){ // 特权函数
return wheelCount;
}
this.setWheelCount = function(count){
wheelCount = count;
}
}
var vehicle = new Vehicle();
vehicle.setWheelCount(5);
var wheel = vehicle.getWheelCount();
alert(wheel);
通过脚本实现。 如
function Vehicle(){
var wheelCount = 4;
this.getWheelCount = function(){
return wheelCount;
}
this.setWheelCount = function(count){
wheelCount = count;
}
}
/* 实现继承 */
function createInheritance(parent,child){
var property;
for(property in parent){
if(!child[property])
child[property] = parent[property];
}
}
function Child(){
}
var child = new Child();
createInheritance(new Vehicle(),child);
alert(child);
var wheelCount = 4;
this.getWheelCount = function(){
return wheelCount;
}
this.setWheelCount = function(count){
wheelCount = count;
}
}
/* 实现继承 */
function createInheritance(parent,child){
var property;
for(property in parent){
if(!child[property])
child[property] = parent[property];
}
}
function Child(){
}
var child = new Child();
createInheritance(new Vehicle(),child);
alert(child);
3。参考文献:
《 Ajax.基础教程》第5章
- javascript高级属性:私有 和 继承
- 5、JavaScript高级之私有属性
- javaScript中私有属性和方法
- Ajax - JavaScript之实现私有属性、像C++和Java一样支持基于类的继承方法之例子
- Python高级特性:私有属性
- java私有属性的继承
- 私有属性private的继承
- Java 拾遗补阙 ----- 继承私有属性
- 子类会继承父类的私有方法和私有属性,只是不能直接访问
- java 子类有没有继承父类的私有属性和私有方法呢 [
- 公有继承和私有继承
- 保护继承和私有继承
- 公有继承和私有继承
- 私有继承和组合
- c++笔记06---继承,公有继承,继承方式对访控属性的影响,私有继承和保护继承
- 继承也可以继承私有属性
- javascript实现私有属性私有方法
- JavaScript学习笔记(二十三) 私有的属性和方法
- 远程调用技术代码追踪(socket)
- 远程调用技术代码追踪(Remobjects第三方控件)
- BizTalk 2004/2006 Interview questions that every developer must know...
- 系统理解Win32andMFC
- 歌词
- javascript高级属性:私有 和 继承
- 远程调用技术代码追踪(webservice)
- 每天一句(十七)
- ASP.NET动态生成静态页面(C#)
- 应用--设计模式的原则
- 页面自定义拖拽布局
- CSS2.0中最常用的18条技巧
- 设计模式
- 直线的多边形裁剪及任意多边形互裁剪