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
/* | |
Structured Javascript | |
* using quotes | |
In C/C++ tradition, use double quotes ("") for strings, and single quotes ('') for characters. | |
If a string contains other strings(such as xml elements), use double quotes for the "outside" quotes, | |
singe quotes for the "inside" quotes. | |
* class declaration | |
Always capitalize class names. |
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 AClass = function () { | |
"use strict"; | |
//Private variables and functions | |
var self = this, | |
priv1 = 66, | |
priv2 = 2, | |
privMethod = function () { | |
return priv2; | |
}, | |
privMethod2 = 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 single = { | |
importantString: "something important", | |
importantObject: new ImportantObject(), | |
importantNumber: 138 | |
}; |
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 Single = new function () { | |
var somethingPrivate = 138; | |
this.importantString = "something important"; | |
this.importantObject = new ImportantObject(); | |
this.importantMethod = function () { | |
returh somethingPrivate + 55; | |
}; | |
}; |
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 MyEvents = function() { | |
"use strict"; | |
var self = this, | |
eventList = {}; | |
this.addEventListener = function(eventName, callback) { | |
if(!eventList[eventName]) { | |
eventList[eventName] = []; | |
} | |
eventList[eventName].push(callback); |
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
/* quick + dirty image preloader */ | |
qdip = { | |
total: 0, | |
loaded: 0, | |
images: {}, | |
load: function(files) { | |
function loaded(file) { | |
qdip.loaded++; | |
qdip.trigger("progress", file); | |
if(qdip.loaded === qdip.total) { |
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
if (!Function.prototype.bind) { | |
Function.prototype.bind = function (oThis) { | |
if (typeof this !== "function") { | |
// closest thing possible to the ECMAScript 5 internal IsCallable function | |
throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable"); | |
} | |
var aArgs = Array.prototype.slice.call(arguments, 1), | |
fToBind = this, | |
fNOP = 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
/* | |
* A speed-improved simplex noise algorithm for 2D, 3D and 4D in Java. | |
* | |
* Based on example code by Stefan Gustavson (stegu@itn.liu.se). | |
* Optimisations by Peter Eastman (peastman@drizzle.stanford.edu). | |
* Better rank ordering method by Stefan Gustavson in 2012. | |
* | |
* This could be speeded up even further, but it's useful as it is. | |
* | |
* Version 2012-03-09 |
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 x = 0, | |
y = 0, | |
dx = 0, | |
dy = -1; | |
for(var i = 0; i < 10; i++) { | |
if( (x == y) || ((x < 0) && (x == -y)) || ((x > 0) && (x == 1-y))){ | |
t = dx; | |
dx = -dy; |
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
#include <v8.h> | |
#include <node.h> | |
#include <iostream> | |
#include <string> | |
using namespace node; | |
using namespace v8; | |
static Handle<Value> foo(const Arguments& args) | |
{ |
OlderNewer