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
| /* library function */ | |
| function async(args, gen){ | |
| return new Promise((resolve, reject) => { | |
| var ite = gen(...args) | |
| !function recur(pre_value){ | |
| var ret = ite.next(pre_value) | |
| ret.done ? resolve(ret.value) : ret.value.then(recur) | |
| }() | |
| }) | |
| } |
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
| Object.defineProperty(Element.prototype, "index", { | |
| get: function(){ | |
| return this.parentElement ? | |
| [].indexOf.call(this.parentElement.children, this) | |
| : | |
| -1 | |
| } | |
| }) | |
| function createUniqueSelector(elem){ |
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 sarope(x, y){ | |
| if(arguments.length === 1){ | |
| var u = x - 0x10000 | |
| var upper = ~~(u / 0x400) + 0xd800 | |
| var lower = ~~(u % 0x400) + 0xdc00 | |
| return {upper, lower} | |
| }else if(arguments.length === 2){ | |
| return 0x10000 + (x - 0xd800) * 0x400 + (y - 0xdc00) | |
| } | |
| } |
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 monitorOverwriteInnerHTML(elem){ | |
| var desc = Object.getOwnPropertyDescriptor(Element.prototype, "innerHTML") | |
| Object.defineProperty(elem, "innerHTML", { | |
| get: function(){ | |
| return desc.get.call(this) | |
| }, | |
| set: function(x){ | |
| console.log(this, x) | |
| desc.set.call(this, x) | |
| } |
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 v = new class B extends class A { | |
| get test(){ | |
| console.log("parent getter") | |
| return this.xxx | |
| } | |
| set test(x){ | |
| console.log("parent setter") | |
| this.xxx = x | |
| } | |
| } { |
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 wait(msec){ | |
| return new Promise((resolve, reject) => { | |
| setTimeout(resolve, msec) | |
| }) | |
| } | |
| function* async_sample(val){ | |
| yield wait(1000) | |
| console.log("after 1second") | |
| console.log(val) |
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 State(data){ | |
| this.prev = null | |
| this.next = [] | |
| this.data = data | |
| this.active = 0 | |
| } | |
| function StateSave(data){ | |
| if(data instanceof State){ | |
| this.current = data |
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 l(val){ | |
| var fn = () => {} | |
| fn.val = val | |
| return new Proxy(fn, { | |
| get: getTrap, | |
| apply: function(target, _this, args){ | |
| if(args.length === 0){ | |
| return target.val | |
| } | |
| var [apply_fn, ...apply_args] = args |
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(helps){ | |
| helps.forEach(e => { | |
| var target = e.target || (typeof e.path === "function" ? e.path() : pathEval(e.path)) | |
| if(typeof target !== "function"){ | |
| console.error("target not found", e) | |
| } | |
| target.toString = () => e.help.map(arg_str => { | |
| var str = Function.prototype.toString.call(target) | |
| var [_, inner] = str.match(/^[^\{]+(\{.+\})$/) || [] |
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 attachHelps(helps){ | |
| Object.keys(helps).forEach(name => { | |
| var target = window[name] | |
| if(typeof target !== "function"){ | |
| throw new Error(`function ${name} not found`) | |
| } | |
| target.toString = () => helps[name].map(arg_str => { | |
| var str = Function.prototype.toString.call(target) |