This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*function roundNumber(number, decimalPlaces) { | |
var decimals = number.toString().split('.')[1]; | |
if (!decimalPlaces) return number; | |
if (!decimals || decimals.length < decimalPlaces) return parseFloat(number); | |
var originalNumDecimalPlaces = number.toString().split('.')[1].length, | |
newNumber = number * Math.pow(10, originalNumDecimalPlaces); | |
for (var i = originalNumDecimalPlaces; i > decimalPlaces; i--) { | |
newNumber = Math.round(newNumber / 10); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Person = (function(){ | |
// all of the Person class definition is encapsulated in this closure | |
// private, class variable | |
var store = []; | |
// constructor | |
var PersonClass = function(name){ | |
this.name = name; | |
store.push(tfhis); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var arr = []; | |
for(var i=0;i<3;i++){ | |
arr.push(i); | |
if(i==2)arr='blah'; | |
console.log('foo',arr); | |
} | |
/* | |
(2) foo [0,1,2] | |
foo blah |