Number.times()





9
Date Submitted Thu. Dec. 21st, 2006 4:09 AM
Revision 1 of 1
Scripter shachi
Tags JavaScript | Number | times
Comments 3 comments
This script lets you do any action the number of times specified.

// the original code

Number.prototype.times = function(str){
var mainstr = "";
for(var i=0;i < this;i++){
mainstr += str;
}
return mainstr;
}

// tweaked

Number.prototype.Times = function(str){
for(var i=0;i < this;i++){
eval(str);
}
}
 

var t = 4;
// using the original function
4.times("a"); // returns "aaa"
// using the tweaked version
4.Times("alert('a')"); // alerts 'a' 4 times
 

Shachi Bista

Comments

Comments Oops!!
Wed. Jan. 3rd, 2007 7:59 AM    Scripter shachi
Comments How do I ....
Wed. Jan. 3rd, 2007 8:01 AM    Scripter shachi
Comments change ur example
Wed. Jan. 3rd, 2007 5:19 AM    Syntax Master sundaramkumar

Voting