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 makePerson = function (name, age) { | |
var me = {}, my = {}; | |
//members | |
my.name = name; | |
my.age = age; | |
//private methods |
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
// Calculate the average of a number of values as they are produced | |
var newAverage = function() { | |
var o = {}; | |
var n = 0; o.n = function() { return n; } // How many values we have, 0 before you add one | |
var total = 0; o.total = function() { return total; } // The total sum of all the given values | |
var minimum = 0; o.minimum = function() { return minimum; } // The smallest value we have seen, 0 before we have any values | |
var maximum = 0; o.maximum = function() { return maximum; } // The largest value we have seen, 0 before we have any values | |
var recent = 0; o.recent = function() { return recent; } // The most recent value you added, 0 before we have any values |
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 newFile = function() { | |
var state = newState(); | |
function close() {//maybe state.close = function() instead | |
if (state.already()) { log('already closed'); return; } | |
}; | |
state.pulse = function() { |
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 start = new Date(); | |
// ---- | |
var size = 10000; | |
var a = []; | |
for (var i = 0; i < size; i++) { | |
a.push(i); |
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 _number(s, base) { | |
if (typeof s !== "string") throw "type"; | |
var n = parseInt(s, base); | |
if (isNaN(n)) throw "data"; | |
if (!match(_numerals(n, base), s)) throw "data"; // Guard against parseInt's dangerously accommodating parsing style by ensuring that the number we made becomes the same text we made it from | |
return n; | |
} |
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
//any type, variable value | |
*a = 7; //make a new variable and set it to 7 | |
a = "hello"; //its a var, so we can set it to something of a different type | |
//one type, variable value | |
Text b; | |
b = "some text"; | |
b = 7; //throws | |
//any type, permanent value |
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
//make something available to the file from within a function in the file | |
//make sure it doesn't affect what's available in files that require this one | |
var color1 = "red"; | |
var color2 = "orange"; | |
//and we want to set two more colors, using the function below | |
function setColors() { | |
var extraColors = {color3:"yellow", color4:"green"}; |
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
//make something available to the file from within a function in the file | |
//make sure it doesn't affect what's available in files that require this one | |
var color1 = "red"; | |
var color2 = "orange"; | |
//and we want to set two more colors, using the function below | |
function setColors() { |
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 color1 = "red"; | |
function set2() { | |
this["color2"] = "orange"; | |
} | |
function set3(destination) { | |
destination["color3"] = "yellow"; | |
} |
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 color1 = "red"; | |
function set2() { | |
this["color2"] = "orange"; | |
} | |
function set3(destination) { | |
destination["color3"] = "yellow"; | |
} |
OlderNewer