JS Object-oriented

Source: Internet
Author: User

Often encountered the effect of the page activity countdown, So wrote a JS countdown method, pulled out, directly quoted Common.js file can be.

Common.js file:

varCountdown = {    " Now":NewDate (),"Lefttime": function (t) {//T parameter format: 2015/2/11 10:08:51        varDT =NewDate (t); varnow = This. Now; vardistime = DT-Now ; if(Distime <=0) {            return; }        varDays = parseint (Distime/( +*3600* -)); varLeftday = parseint (distime% ( +*3600* -)); varHours = parseint (Leftday/( +*3600)); varLefthour = parseint (leftday% ( +*3600)); varminutes = parseint (Lefthour/( +* -)); varLeftminute = parseint (lefthour% ( +* -)); varseconds = parseint (Leftminute/( +)); varShowday = (Days <Ten) ? ('0'+days.tostring ()): Days.tostring (); varShowhour = (Hours <Ten) ? ('0'+hours.tostring ()): Hours.tostring (); varShowminute = (Minutes <Ten) ? ('0'+minutes.tostring ()): Minutes.tostring (); varShowsecond = (Seconds <Ten) ? ('0'+seconds.tostring ()): Seconds.tostring (); returnShowday +"|"+ Showhour +"|"+ Showminute +"|"+Showsecond; }};

Pages to use:

<script src="@Url. Content ("~/common.js")"Type="Text/javascript"></script>"Text/javascript">varTime ="2015/3/11 10:01:15"; varValue =Countdown.lefttime (time); varTimes = Value.split ('|'); Alert (times[0] +"days"+ times[1] +"when"+ times[2] +"points"+ times[3] +"seconds");</script>

=============================================================================================

Additional JS object-oriented knowledge: http://www.iteye.com/topic/434462

 //  1th syntax   function Circle (r) { this . R = R;      } circle.pi  = 3.14159  ; Circle.prototype.area  = function () { ret Urn  Circle.pi * this . R * this  .R;  var  C = new  Circle (1.0  );   Alert (C.area ()); 
 //  2nd syntax  var  Circle = function () { var  ob         j = new   Object (); Obj.                  PI  = 3.14159  ; Obj.area  = function (r) { return this .         PI * r * R;       return   obj;  var  C = new   Circle ();  Alert (C.area ( 1.0 )); 
 //  3rd syntax  var  Circle = new   Object ();      Circle.pi  = 3.14159  ; Circle.area  = function (r) { return  this .      PI * r * R;  } alert (Circle.area ( 1.0 )); 
 //  4th syntax  var  circle={  " pi  : 3.14159  ,   area   " :function (R) { return  
     
      this 
     .              PI * r * R;      }      };  Alert (Circle.area ( 1.0 )); 
    // The 5th kind  of notation    var New Function ("this. PI = 3.14159;this.area = function (r) {return r*r*this. PI;} " );            Alert ((new Circle ()). Area (1.0));  

Especially the last two kinds, often see.

JS Object-oriented

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.