javascript模仿c#的问题,高手进~~~~~
最近想做一组ajax控件,做了几个后,发现客户端脚本一大堆一样,想来个和c#一样的继承,override。发现无法实现啊,高手们指教一下吧。
下面给了一段代码,我想在class B中override fn1,不知道怎么写下去了。
c#
class A
{
public A()
{
this.fn1();
}
public virtual void fn1()
{
}
}
class B : A
{
public override void fn1()
{
base.fn1();
// do something
}
}
javascript
function A() {
this.fn1();
}
function A_fn1() {
}
A.prototype.fn1 = A_fn1;
function B() {
}
B.prototype = new A(); --------------------编程问答-------------------- 微软的例子,Employee继承自Person,出处:http://ajax.asp.net/docs/tutorials/EnhancingJavaScriptTutorial.aspx
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);
--------------------编程问答-------------------- 晕了,我的ajax是自己的实现阿,我并没有使用altas框架阿。 --------------------编程问答-------------------- 这个就是javascript支持的,并不需要框架支持,而且那个是asp.net ajax的,也不是atlas。 --------------------编程问答-------------------- 对,用 prototype --------------------编程问答-------------------- Type.registerNamespace是什么东西,标准javascript支持么?
补充:.NET技术 , ASP.NET