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
//test |
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
// Promise.all is good for executing many promises at once | |
Promise.all([ | |
promise1, | |
promise2 | |
]); | |
// Promise.resolve is good for wrapping synchronous code | |
Promise.resolve().then(function () { | |
if (somethingIsNotRight()) { | |
throw new Error("I will be rejected asynchronously!"); |
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
// Constructor way | |
function SingletonKlass() { | |
var instance; | |
SingletonKlass = function SingletonKlass() { | |
return instance; | |
} | |
SingletonKlass.prototype = this; | |
instance = new SingletonKlass(); |
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
<body> < div id = "box" style = "position:relative;display:inline;" > Bird! </div> | |
</body> | |
<script> | |
var timers = { | |
timerID: 0, | |
timers: [], | |
add: function (fn) { | |
this.timers.push(fn); | |
}, | |
start: 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
/* # bind() function - 3 impls that works | |
* @ sample: | |
* var newFunc = obj.someFunc.bind(myobj, 1, 2, 3); | |
*/ | |
//pre ECMA5 bind function: | |
// 《js Pattern》 version | |
if (typeof Function.prototype.bind === "undefined") { | |
Function.prototype.bind = function (thisArg) { |
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 inherit(Child, Parent) { | |
Child.prototype = new Parent(); //this is the prototype inhert magic! | |
} | |
var holyInherit = (function () { | |
var F = function () {}; | |
return function (C, P) { | |
F.prototype = P.prototype; | |
C.prototype = new F(); | |
C.uper = P.prototype; |
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
// constructor | |
var Gadget = (function () { | |
// static variable/property | |
var counter = 0, | |
NewGadget; | |
// this will become the | |
// new constructor implementation | |
NewGadget = function () { | |
counter += 1; | |
}; |
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 flexisum(a) { | |
var total = 0; | |
for (var i = 0; i < arguments.length; i++) { | |
var el = arguments[i], | |
num; | |
if (el == null) { | |
continue; | |
} else { | |
if (isArray(el)) { | |
num = flexisum.apply(this, el); //recursion -- deep calculate |
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
<iframe width="100%" height="300" src="http://jsfiddle.net/Williammer/Yp9gf/1/embedded/" allowfullscreen="allowfullscreen" frameborder="0"></iframe> | |
<script> | |
/** javaScript **/ | |
var findNodes = function (callback, callback_obj) { | |
var i = 10, | |
nodes = [], | |
found; | |
// check if callback is callable |
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> | |
<meta property="wb:webmaster" content="edcf77ed05a8765f" /> | |
<meta name="viewport" content="width=device-width"> | |
<style> | |
#result li.passed { color: blue; } | |
#result li.failed { color: red; } |
NewerOlder