Jump to content

Js Advanced Syntax (Prototype)?


tinfanide
 Share

Recommended Posts

function zxcScroller(o){var mde=typeof(o.Mode)=='string'&&o.Mode.charAt(0).toUpperCase()=='V'?['top','height','offsetTop','offsetHeight']:['left','width','offsetLeft','offsetWidth'],obj=document.getElementById(o.ID),slide=obj.getElementsByTagName('DIV')[0],slider=document.createElement('DIV'),clds=slide.getElementsByTagName('*'),lst=clds[clds.length-1],sz,nu,z0=0,ms=o.Duration,ud=o.Direction;obj.style.overflow='hidden';slider.style.position='absolute';slider.style.left='0px';slider.style.top='0px';obj.appendChild(slider);slide.style.position='absolute';slide.style[mde[1]]='20000px';sz=lst[mde[2]]+lst[mde[3]];nu=Math.ceil(obj[mde[3]]/sz)+1;for (;z0<nu;z0++){  slide=z0>0?slide.cloneNode(true):slide;  slide.style[mde[0]]=z0*sz+'px';  slider.appendChild(slide);}this.ms=typeof(ms)=='number'?ms*1000:10000;this.obj=slider;this.mde=mde[0];this.sz=-sz;this.ud=typeof(ud)=='number'&&ud<0?true:false;this.now=this.ud?0:this.sz;this.to=null;this.scroll();}zxcScroller.prototype={Scroll:function(ud){  this.Pause();  this.ud=typeof(ud)=='number'&&(ud==1||ud==-1)?ud<0?true:false:typeof(ud)=='string'?!this.ud:this.ud;  this.ms=typeof(ud)=='number'&&ud>1?ud*1000:this.ms;  var oop=this;  this.to=setTimeout(function(){ oop.scroll(); },200);},Pause:function(){  clearTimeout(this.to);},scroll:function(){  this.Pause();  var f=this.now,t=this.ud?this.sz:0;  this.animate(f,t,new Date(),this.ms*Math.abs((t-f)/this.sz));},animate:function(f,t,srt,mS){  var oop=this,ms=new Date().getTime()-srt,now=(t-f)/mS*ms+f;  if (isFinite(now)){   this.now=now;  }  this.obj.style[this.mde]=this.now+'px';  if (ms<mS){   this.to=setTimeout(function(){ oop.animate(f,t,srt,mS); },10);  }  else {   this.now=this.ud?0:this.sz;   this.scroll();  }}}

The longer I've been learning JS, the more I wanna ask what the syntax of the codes above

zxcScroller.prototype={Scroll:function(ud){  this.Pause();  this.ud=typeof(ud)=='number'&&(ud==1||ud==-1)?ud<0?true:false:typeof(ud)=='string'?!this.ud:this.ud;  this.ms=typeof(ud)=='number'&&ud>1?ud*1000:this.ms;  var oop=this;  this.to=setTimeout(function(){ oop.scroll(); },200);},Pause:function(){  clearTimeout(this.to);},scroll:function(){  this.Pause();  var f=this.now,t=this.ud?this.sz:0;  this.animate(f,t,new Date(),this.ms*Math.abs((t-f)/this.sz));},animate:function(f,t,srt,mS){  var oop=this,ms=new Date().getTime()-srt,now=(t-f)/mS*ms+f;  if (isFinite(now)){   this.now=now;  }  this.obj.style[this.mde]=this.now+'px';  if (ms<mS){   this.to=setTimeout(function(){ oop.animate(f,t,srt,mS); },10);  }  else {   this.now=this.ud?0:this.sz;   this.scroll();  }}

are called??? I hardly see them in the W3schools tutorial. Are they advanced stuff in JS?

Link to comment
Share on other sites

The prototype of an object will set or return the default property values of instances of the object.
Yes, I know some bit of prototype. Just not used to it, though. Because basically I do JS like
function (){}

But I see lots of people doing stuff like

var sth = {sth: function(){}}sth.sth()

And always use this. in their scripts.It just looks scary to me. Very hard to comprehend a line of those.So wonder what the syntax or this way of scripting is called.

Link to comment
Share on other sites

They're just using objects.That syntax is called JSON. It's the same as creating a new Object and adding properties one by one.

var A = new Object();a.method = function() {} var A = {  method: function() {}}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...