网络编程
位置:首页>> 网络编程>> JavaScript>> javascript中实现override,overload和类似c#中的property

javascript中实现override,overload和类似c#中的property

作者:normanzb 来源:无忧脚本 发布时间:2008-05-16 12:01:00 

标签:Override,类,javascript

先把这个script加到你的页面里:

http://code.google.com/p/doufu/source/browse/trunk/nsc.js

实现一个基础类和继承类:


在上面的类中,我们可以用this.OverrideMethod实现类似Override的功能, 例子


用This.NewProperty实现类似Property 的功能


BaseClassA = function()
{
 nsc.OOP.Class(this);

 // Create Properties
 var _noun = "world";
 this.NewProperty("Noun");
 this.Noun.Get = function()
 {
  return _noun;
 }
 this.Noun.Set = function(value)
 {
  _noun = value;
 }
 
 var _count = 0;
 this.NewProperty("Count");
 this.Count.Get = function()
 {
  return _count;
 }
 this.Count.Set = function(value)
 {
  _count = value;
 }
}

并且在一些特殊情况下,允许直接使用 this.属性名 来取得get方法的返回值:


用this.OverloadMethod实现overload:

this.OverloadMethod("方法名", function()
{
  //coding here
});

overload method 的sample代码等等写

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com