偶是一位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"
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"
}