我爱Aspx >> Asp.Net >> Javascript综合使用JavaScript中也可以实现私有属性,而且JavaScript也能像C++和Java一样支持基于类的继承方法。为了展示这些是怎样实现的,下面说明如何转换前面使用Vehicle、SportsCar和CementTruck对象的例子,从而使用信息隐藏和继承的新模式。代码清单5-5列出了新的对象定义。
代码清单5-5 classicalInheritance.js
function Vehicle() {
var wheelCount = 4;
var curbWeightInPounds = 4000;
this.getWheelCount = function() {
return wheelCount;
}
this.setWheelCount = function(count) {
wheelCount = count;
}
this.getCurbWeightInPounds = function() {
return curbWeightInPounds;
}
this.setCurbWeightInPounds = function(weight) {
curbWeightInPounds = weight;
}
this.refuel = function() {
return "Refueling Vehicle with regular 87 octane gasoline";
}
this.mainTasks = function() {
return "Driving to work, school, and the grocery store";
}
}
function SportsCar() {
this.refuel = function() {
Ҷƪл˵?
JavaScript中基于类的继承[05-20]
私有属性和使用JavaScript的信息..[05-20]
通过prototype属性建立面向对象的..[05-20]
使用JSDoc建立JavaScript代码的文..[05-20]
使用JSLint完成JavaScript语法检..[05-20]
完成JavaScript压缩和模糊处理[05-20]
JavaScript本地图片预览程序[05-20]
三种JavaScript进度条[05-20]
超酷JavaScript菜单类[非常漂亮][05-20]
JavaScript实现AJAX的拖动效果[05-20]
JavaScript中基于类的继承[05-20]
私有属性和使用JavaScript的信息..[05-20]
通过prototype属性建立面向对象的..[05-20]
使用JSDoc建立JavaScript代码的文..[05-20]
使用JSLint完成JavaScript语法检..[05-20]
完成JavaScript压缩和模糊处理[05-20]
使用Firefox的Web开发扩展包[05-20]
微软提供的ASP.NET 2.0空间,你还..[05-20]
JavaScript本地图片预览程序[05-20]
Visual Studio 2005 中的新的 Da..[05-20]