偶是一位JS菜鸟,最近学AJXA的的时候在一个国外的网站里发现如下的一段JS代码:var $$=function(_1){
return new ElementWrapper(_1);
};
var ElementWrapper=function(_2){
if(_2.nodeType==1){
this.id=_2.id||(_2.id=ElementWrappers.getNewId());
}else{
this.id=_2;
}
};
ElementWrapper.prototype={getElement:function(){
return $(this.id);
},getId:function(){
return this.id;
},getHeight:function(){
return this.getComputedDimension("height","offsetHeight");
},getWidth:function(){
return this.getComputedDimension("width","offsetWidth");
},getTop:function(){
return this.getOffset("offsetTop");
},getLeft:function(){
return this.getOffset("offsetLeft");
},getBottom:function(){
return this.getTop()+this.getHeight();
},getRight:function(){
return this.getLeft()+this.getWidth();
},getOffset:function(_3){
var el=this.getElement();
var x=0;
while(el.offsetParent&&el.offsetParent!=document.documentElement){
x+=el[_3];
el=el.offsetParent;
}
return x;
},getComputedStyle:function(_6){
var el=this.getElement();
if(document.defaultView&&document.defaultView.getComputedStyle){
return document.defaultView.getComputedStyle(el,null).getPropertyValue(_6);
}else{
if(el.currentStyle){
return el.currentStyle[_6];
}else{
return null;
}
}
通常我们想申明一个函数的格式是"function $$(){}"这样的吧
而他用的都是类似"var $$=function(_1){"这样的格式,实在搞不明白
望高手解疑~~~~
全部原代码见"http://www.netflix.com/BrowseSelection?lnkctr=nmhbs"

解决方案 »

  1.   

    js里函数本身也是对象, xxx = function(){}相当于 xxx = new Funtion(); 可以把xxx看作函数指针。
      

  2.   

    正宗的js  不喜欢用 function aaa () {
    }
      

  3.   

    var aaa = function (){}
      

  4.   

    其实看习惯了也还好,甚至说看上去很精炼,呵呵现在难得有这么点时间系统重学javascript~~
      

  5.   

    btbtd兄弟,说实话我没写过过万行的js程序,不过其它语言的程序还是写过的,我喜欢看到这种排列方式,所以说“看上去很精炼”。你也没必要太激动了~~^_^!