Icontem

File: example.js

Recommend this page to a friend!
  Classes of martin barker  >  extendm.js  >  example.js  >  Download  
File: example.js
Role: Example script
Content type: text/plain
Description: Example File showing the uses of the system
Class: extendm.js
Extend the Number object with more functions
Author: By
Last change: Matching document layout
Date: 6 years ago
Size: 1,066 bytes
 

Contents

Class file image Download
/*
  extendm.js adds some simple maths system into the base Number object of JS meaning you dont need to define methods in your code check certain things
*/

// isInt & isFloat
var test1 = 1;
var test2 = 1.4;

test1.isInt(); // returns true;
test1.isFloat(); // returns false;
test2.isInt(); // returns false;
test2.isFloat(); // returns true;

// isEven & isOdd
var test1 = 1;
var test2 = 2;

test1.isEven(); // returns false;
test1.isOdd(); // returns true;
test2.isEven(); // returns true;
test2.isOdd(); // returns false;

// random numbers
Number.random(); // returns a random number
Number.random(19); // returns a random number between 0 and 19
Number.random(10,20); // returns a random number between 10 and 20

// date support
var test = 1378032235;
test.toDate();// returns Date Object in "Sun Sep 01 2013 11:43:55 GMT+0100 (GMT Daylight Time)"

// to boolean
var test1 = 0; 
test1.toBoolean(); // returns true;
var test2 = 1; 
test2.toBoolean(); // returns false;
var test3 = 2; 
test3.toBoolean(); // throws exception