ASP.NET AJAX的面向对象思想--访问修饰与继承
来源:互联网 发布:网络举报 编辑:程序博客网 时间:2024/05/19 13:44
下面的脚本实例有两个类Person和Employee,Employee从Person继承而来,两个类示范了私有字段的使用,它们都有公共属性、方法。另外Employee类重写了Person类的toString实现,并调用了基类的功能。
Type.registerNamespace("Demo");
Demo.Person = function(firstName, lastName, emailAddress) {
this._firstName = firstName;
this._lastName = lastName;
this._emailAddress = emailAddress;
}
Demo.Person.prototype = {
getFirstName: function() {
return this._firstName;
},
getLastName: function() {
return this._lastName;
},
getEmailAddress: function() {
return this._emailAddress;
},
setEmailAddress: function(emailAddress) {
this._emailAddress = emailAddress;
},
getName: function() {
return this._firstName + ' ' + this._lastName;
},
dispose: function() {
alert('bye ' + this.getName());
},
sendMail: function() {
var emailAddress = this.getEmailAddress();
if (emailAddress.indexOf('@') < 0) {
emailAddress = emailAddress + '@example.com';
}
alert('Sending mail to ' + emailAddress + ' ...');
},
toString: function() {
return this.getName() + ' (' + this.getEmailAddress() + ')';
}
}
Demo.Person.registerClass('Demo.Person', null, Sys.IDisposable);
Demo.Employee = function(firstName, lastName, emailAddress, team, title) {
Demo.Employee.initializeBase(this, [firstName, lastName, emailAddress]);
this._team = team;
this._title = title;
}
Demo.Employee.prototype = {
getTeam: function() {
return this._team;
},
setTeam: function(team) {
this._team = team;
},
getTitle: function() {
return this._title;
},
setTitle: function(title) {
this._title = title;
},
toString: function() {
return Demo.Employee.callBaseMethod(this, 'toString') + '/r/n' + this.getTitle() + '/r/n' + this.getTeam();
}
}
Demo.Employee.registerClass('Demo.Employee', Demo.Person);
Inheritance.js脚本文件中定义了两个类:Person和Employee,Employee是从Person继承而来。每个类都有字段、公共属性和方法。另外,Employee类重写了toString的实现,并在重写的代码中调用了基类的功能。在这个例子中把类Person的名字空间设定为"Demo"。运行页面Inheritance.aspx,点击“创建对象”、“对象释放”、“公共和私有属性”、“对象方法”、“重写方法”,“对象类型检查”体验一下。
- ASP.NET AJAX的面向对象思想--访问修饰与继承
- 剖析ASP.NET AJAX的面向对象思想
- 剖析ASP.NET AJAX的面向对象思想
- ASP.NET AJAX的面向对象思想--接口
- ASP.NET AJAX的面向对象思想--枚举
- 剖析ASP.NET AJAX的面向对象思想
- [转]剖析ASP.NET AJAX的面向对象思想和ASP.NET AJAX的组件开发
- ASP.NET AJAX的面向对象思想--类、成员和名字空间
- 在ASP.NET中面向对象的编程思想
- >+ 在ASP.NET中面向对象的编程思想
- 在ASP.NET中面向对象的编程思想
- 在ASP.NET中面向对象的编程思想
- 在ASP.NET中面向对象的编程思想
- 在ASP.NET中面向对象的编程思想
- 在ASP.NET中面向对象的编程思想
- 在asp.net中面向对象的编程思想
- 在ASP.NET中面向对象的编程思想
- 在ASP.NET中面向对象的编程思想
- 11个处于悬崖边缘的 Web 公司
- 潜能开发自我修习手册
- ASP.NET AJAX的面向对象思想--类、成员和名字空间
- 在VM虚拟机器redhat9下安裝vmware-tool的方法
- sqlserver错误状态
- ASP.NET AJAX的面向对象思想--访问修饰与继承
- ASP.NET AJAX的面向对象思想--接口
- ASP.NET AJAX的面向对象思想--枚举
- document.body.scrollTop 值总为0的解决方法
- Mysql修改默认编码linux
- Slop One算法-Collaborative Filtering
- 心情
- 服务器应用程序不可用 .net aspx 配置问题
- 90后心目中的“生活守则”是什么