foo.oOffset = {x:e.layerX, y:e.layerY };
等价于:
foo.oOffset = {x:e.layerX, y:e.layerY };
相当于:
foo.oOffset = new Object;
foo.oOffset["x"] = e.layerX;
foo.oOffset.y = e.layerY
__namespace__({core:{common:{collection:
(function(){
... statement ...
return {Collection:Collection,Iterator:Iterator,Enumerable:Enumerable,List:List,Dict:Dict,Pair:Pair};
})()
}}});
这是一个关于core对象的common对象的collection对象 的问题 的问题 的问题。
把core.common.collection的值,即闭包匿名函数的返回值(包括6个属性),传递给__namespace__函数
代码太长,中间部分省略了,其实这部分才是关健部分,最后所返回的这6个属性又各有自己的方法、属性,如第一个属性的代码为:
var Collection={
__name__:"<Interface>Collection",
__doc__:function(){
/**
A collection represents a group of objects, known as its elements
**/
},
size:__abstract__,
isEmpty:function()
{
/**
isEmpty(void) --> boolean
isEmpty is defined by collection interface
You can override this method by yourself
@returns boolean
**/
return this.size() == 0;
},
toArray:__abstract__,
add:__abstract__,
contains:__abstract__,
remove:__abstract__,
append:function(collection)
{
/**
append(collection) --> Collection
append is defined by collection interface
You can override this method by yourself
@returns collection
**/
var ret = this.clone();
if(collection.isKindOf(Iterator))
{
var it = collection.iterator();
do
{
ret.add(it.next());
}while(it.hasNext());
}
else
{
var li = collection.toArray();
for (var i = 0; i < li.length; i++)
{
ret.add(li[i]);
}
}
return ret;
},
clear:__abstract__
JS中冒号用法
1、在vbs中,可以调用一些内置函数(如mid()replace()等来进行对字符串的操作),而在js中,我们则是用String中的方法来操作的(如s.indexOf(",")等),也就是说,我们所创建的字符串,都是对象?狭义上说,可以这么认为在《javascript difinition guid》里指出,当我们调用如s.indexOf(",")的方法时,js把s这个变量生成了一个瞬时的对象,也就是一个包装wrapper,当我们调用indexOf方法时,实际上,s在调用方法时就是一个对象。
以下这个常用的方法,我个人觉得这也是一个wrapper。但是他不是瞬时的。 <SCRIPT LANGUAGE="JavaScript"> <!-- function getName() { return { first : "blue", second : "Destiny" }; }; var name=getName(); alert(name.first) alert(name.second) //--> </SCRIPT> 输出结果: blue Destiny
2、js里的变量命名规则,一般情况下,我们的命名规则应该是以下划线、字母、以及数字来构成。但在js里,变量的命名很有趣。下面来看一个例子。 <SCRIPT LANGUAGE="JavaScript"> <!-- function $() { this.这是什么="这是javascript"; alert(this.这是什么) } $(); //--> </SCRIPT> 输出结果: 这是javascript
很惊讶吧,:),可以用中文来命名!
|