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
| import lazy from './lazy-error.js'; | |
| const fn = lazy(); | |
| function test() { | |
| fn(); | |
| } | |
| test(); |
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
| if (!Function.prototype.bindSoft) { // set once | |
| const originalFunctionSymbol = Symbol(); | |
| Function.prototype.bindSoft = function(thisValue) { | |
| const originalFunction = this; | |
| const boundFunction = originalFunction.bind(thisValue); | |
| // store pointer to original function | |
| boundFunction[originalFunctionSymbol] = originalFunction; | |
| return boundFunction; | |
| }; |
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 cloneFunction(fn, mode = 'primitive') { | |
| var clonedFn; | |
| if (mode === 'primitive') { | |
| clonedFn = fn; | |
| } else if (mode === 'construct') { | |
| clonedFn = new Function('return ' + fn.toString())(); | |
| } else if (mode === 'wrap') { | |
| let Constructor; | |
| clonedFn = function() { |
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
| <HTML> | |
| <HEAD> | |
| <TITLE>JavaScript Example 14</TITLE> | |
| </HEAD> | |
| <BODY> | |
| <FORM name="form1"> | |
| <INPUT type="text" name="text1" size="25" value=""> | |
| </FORM> | |
| <script> | |
| window.GLOBAL_ARRAY = []; |
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
| // will return a cloned version of rootNode descendants | |
| // in itself this function is useless but it can be modified to add custom cloning behaviour | |
| function cloneNodeDeep(rootNode) { | |
| var node = rootNode; | |
| var rootClone = document.createDocumentFragment(); | |
| var nodeClone = rootClone; | |
| while (node) { | |
| var nextNode = null; | |
| var firstChild = node.firstChild; | |
| if (firstChild) { |
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 readNodeAt(rootNode, path) { | |
| var i = 0; | |
| var j = path.length; | |
| var index; | |
| var found = rootNode; | |
| for (;i < j; i++) { | |
| index = Number(path[i]); | |
| found = found.childNodes[index]; | |
| if (found === null) { |
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 Promise = require('bluebird'); | |
| var fs = Promise.promisifyAll(require('fs')); | |
| var existingFile = 'path/to/existing/file'; | |
| var unexistingFile = 'path/to/unexisting/file'; | |
| var statPromise = fs.stat(existingFile); | |
| function onStatResolution(stat){ | |
| return fs.readFile(unexistingFile); | |
| } |
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
| <!doctype html> | |
| <html> | |
| <head> | |
| </head> | |
| <body> | |
| <div class="countdown"> | |
| </div> |
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 Lang = { | |
| name: undefined, | |
| availables: ['fr', 'en', 'de'], | |
| detect: function(){ | |
| var languages = window.navigator.languages, preferredLanguage; | |
| if( languages ){ | |
| languages = languages.map(function(language){ | |
| var lang; |
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
| // http://stackoverflow.com/questions/21961839/simulation-background-size-cover-in-canvas | |
| function drawImageProp(ctx, img, x, y, w, h, offsetX, offsetY) { | |
| if (arguments.length === 2) { | |
| x = y = 0; | |
| w = ctx.canvas.width; | |
| h = ctx.canvas.height; | |
| } | |
| // default offset is center | |
| offsetX = typeof offsetX === "number" ? offsetX : 0.5; |