Showing posts with label JavaScript. Show all posts
Showing posts with label JavaScript. Show all posts

Thursday, March 22, 2012

Javascript Object oriented programming

I forget the style of JS class.

Define class object
//Define class 
function Class1(val1, val2){
  //Define propaties
  this.val1 = val1;
  this.val2 = val2;
}


Define method
Class1.prototype.getVal1 = function getVal1_Class1(){
  return this.val1;
}

Create class instance

var instance1 = Class1(10,20);

Wednesday, March 21, 2012

JavaScript zero padding

I don't know that javascript don't have 0 padding method looks like toString(2).
But some people found the answer.

Ex. 2digit padding
("0" + value).slice(-2)

Ex. 5digit padding
("0000"+value).slice(-5)