JScript .NET(像 JScript 一样)通过基于原型的对象支持继承。JScript .NET 还允许声明定义对象数据和行为的类,从而支持基于类的对象。在 JScript .NET 中创建的类可由任何 .NET 语言使用和扩展。类可以继承基类的属性和方法。可以对类和类成员应用几种属性,修改它们的行为和可见性。详细资料请参看Visual Studio .Net文档
解决方案 »
- 我要实现图片间歇向上滚动,但循环滚动两次后就自动停止,有哪位大侠知道什么原因,谢谢
- 向sysdzw提问js的问题
- 整理了下自己写的框架类,欢迎板砖~!
- 200分求助 EXT高手
- JS操作table,关于删除列
- jQuery easyui下拉菜单被layout遮挡
- 正在提交表单数据,请稍侯 ......
- 关于标签的name值改成变量的问题
- !!!!!!!!!!!穷人跪求!!!!!!!!!!!!!!!!
- 如何控制一个table里的内容由右到左循环滚动,不留空白.
- 在主页面应用了iframe框架,点击按钮执行本页的一个函数,怎样将函数里的参数传到iframe的src文件内,并且iframe下的文件能立刻响应该参
- asp,数据库,javascirpt问题
function String.prototype.Trim() {return this.replace(/(^\s*)|(\s*$)/g,"");}
就像C語言.可以用結構模擬封裝,用指針函數模擬類的方法但是你無論如何你也不能做到繼承和多態(這不是我說的.是後老實說的!)JS是Base--Object.所以只能簡單的模擬封裝.其他的如重載,繼承,多態不是你想不想的問題.更本就沒提供這個機制!T0 meizz(梅花雨)你是讓我看這是重載的例子麼..如果是.我勸你回去看看重載的概念...
查一下prototype,可用对象的原型属性来给对象增加方法和属性
function testClass()
{
this.property1 = ""; if (arguments.length==0)
{
this.property1 = "runmin";
}
else
{
this.property1 = arguments[0];
}
}var tmp = new testClass();alert(tmp.property1);var tmp1 = new testClass("ws");alert(tmp1.property1);</script>
//--start---------
function Major()
{
if ( !Major.defined )
{
Major.defined = true;
Major.Prototype = Major;
Major.Prototype();
}
else if ( this == Major )
{
this.attribute1 = 1;
this.attribute2 = 2;
this.func1 = function()
{
var a = 0;
}
this.func2 = function()
{
var b = 0;
}
}
else
{
for ( key in Major )
{
this[key] = Major[key];
}
}
}function Sub()
{
if ( !Sub.defined )
{
Sub.defined = true;
Sub.Prototype = Sub;
Sub.Prototype();
}
else if ( this == Sub )
{
this.Subattribute1 = 3;
this.Subattribute2 = 4;
this.Subfunc1 = function()
{
var a = 0;
}
this.Subfunc2 = function()
{
var b = 0;
}
}
else
{
for ( key in Sub )
{
this[key] = Sub[key];
}
}
}function define( subclass, baseclass )
{
if ( !baseclass.defined )
{
new baseclass;
}
if ( !subclass.defined )
{
new subclass;
}
for ( key in baseclass )
{
subclass[key] = baseclass[key];
}
}define( Sub, Major );var subobject = new Sub;
var baseobject = new Major;
var a = 0;
//--End-----------//以上用来说明类的继承的算法
//一个精简的类定义看起来应该象下面这个样子function menu()
{
if ( inherit( this, menu, baseobject ) )
{
this.prototype=
{
text: "Buddy Board Service", //成员变量
backcolor: "gray",
onClick : function() //成员函数
{
},
onSelect: function()
{
}
}
var staticVariable = 1; //相当于类的静态变量但要通过成员函数操作 this.getStaticVariableValue() //成员函数
{
return staticVariable;
}
this.getStaticVariableValue( value )
{
staticVariable = value;
}
}
}
function YourClass()
{
//你的属性
this.Name="test";
this.Value="测试"; this.Create=YourClass_Create;
}function YourClass_Create()
{
this.CreatedBy="YourClass";
}//定义子类
function YourSubClass()
{
//继承父类
this.ParentInherited=YourClass;
this.ParentInherited(); //重写方法
this.Create=YourSubClass_Create;
}function YourSubClass_Create()
{
YourClass_Create();
this.CreatedBy = this.CreatedBy + ",子类";
}由于是现写的,没有测试。大致思路就是这样的
简单比什么都好。
而且做一个核心的编程框架也就个两三天,一劳永逸,何乐而不为。