分类: Java
2007-04-22 13:34:54
javascript没有类
//--------------严格说来只是一个哈希表,不算是类
function TPoint(X, Y)
{
this.X = X;
this.Y = Y;
this.MoveBy = TPoint_MoveBy;
}
function TPoint_MoveBy(DeltaX, DeltaY)
{
this.X += DeltaX;
this.Y += DeltaY;
}
// -------- Demo
function Demo()
{
var P = new TPoint(3, 4);
P.MoveBy(5, 6);
alert("X: " + P.X + "\nY: " + P.Y);
}
同意楼上
function Folder(folderDescription, hreference)
{
this.desc = folderDescription
this.hreference = hreference
this.id = -1
this.navObj = 0
this.iconImg = 0
this.nodeImg = 0
this.isLastNode = 0
this.isOpen = true
this.iconSrc = "../images/tree/wwdfolderopen.gif"
this.children = new Array
this.nChildren = 0
this.initialize = initializeFolder
this.setState = setStateFolder
this.addChild = addChild
this.createIndex = createEntryIndex
this.escondeBlock = escondeBlock
this.esconde = escondeFolder
this.mostra = mostra
this.renderOb = drawFolder
this.totalHeight = totalHeight
this.subEntries = folderSubEntries
this.outputLink = outputFolderLink
this.blockStart = blockStart
this.blockEnd = blockEnd
}
function initializeFolder(level, lastNode, leftSide)
{
.........
}
我还在这个网页()找到相关javascrip 类的定义,重要的代码如下:
function WuYouUser()
{
this.Name;
this.ArticleCount = 0;
this.NewArticle = function()
{
this.ArticleCount++;
}
}
既然定义好了这个方法,我们来试试效果如何:
var Wo = new WuYouUser();
Wo.NewArticle();
document.write(Wo.ArticleCount);
可以看到输出了1。