This file contains hidden or 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
| window.onkeypress = function(event) { | |
| console.log(event.which || event.keyCode); | |
| }; |
This file contains hidden or 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
| alert('Hello!'); |
This file contains hidden or 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 canvasX, canvasY; | |
| theCanvas.onmousemove = transformIntoCanvasRelative; | |
| function transformIntoCanvasRelative(evt) { | |
| var canvas = evt.target; | |
| var rect = canvas.getBoundingClientRect(); | |
| canvasX = evt.clientX - rect.left; | |
| canvasY = evt.clientY - rect.top; | |
| } |
This file contains hidden or 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
| /* | |
| Used to include another JS file. | |
| */ | |
| FIB_URL = 'https://gist.githubusercontent.com/lodr/6879872/raw/1dd7315fbac1194abf40406331cf825f74b71ccb/fib.js'; | |
| importScripts(FIB_URL); | |
| /* | |
| This is used to receive data from the parent. | |
| */ | |
| onmessage = function(evt) { |
This file contains hidden or 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 fib(x) { | |
| if (x <= 2) return 1; | |
| return fib(x-1) + fib(x-2); | |
| } |
This file contains hidden or 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
| load([ | |
| {"task":"HTML I","done":true}, | |
| {"task":"CSS","done":true}, | |
| {"task":"Responsive design","done":true}, | |
| {"task":"Git","done":true}, | |
| {"task":"JavaScript I","done":true}, | |
| {"task":"JavaScript II","done":false} | |
| ]); |
This file contains hidden or 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 fPromise(timeout, result, error) { | |
| return new Promise(function(fulfill, reject) { | |
| setTimeout(function () { | |
| if (!error) fulfill(result); | |
| else if (error instanceof Error) throw error; | |
| else reject(error); | |
| }, timeout); | |
| }); | |
| } |
This file contains hidden or 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 retry(target, keepTrying) { | |
| var retryCount = 1; | |
| var fulfill, reject; | |
| var promise = new Promise(function (f, r) { | |
| fulfill = f; | |
| reject = r; | |
| }); | |
| realRetry(); |
This file contains hidden or 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.prototype.retryWhile = function(keepTrying) { | |
| var target = this; | |
| var retryCount = 1; | |
| var fulfill, reject; | |
| var promise = new Promise(function (f, r) { | |
| fulfill = f; | |
| reject = r; | |
| }); | |
This file contains hidden or 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 PromiseChain() { this._current = null; } | |
| PromiseChain.prototype.add = function (task) { | |
| if (this._current === null) { | |
| this._current = task(); | |
| } | |
| else { | |
| var next = function () { return task(); }; | |
| this._current = this._current.then(next, next); | |
| } |
OlderNewer