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
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
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 ILS(store_name, db_name){ | |
var self = this | |
store_name = store_name || "default" | |
db_name = db_name || "ILS" | |
Object.defineProperties(this, { | |
"store_name": { | |
value: store_name, | |
writable: false | |
}, | |
"db_name": { |
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 AFunc(fn){ | |
if(typeof fn !== "function") throw new TypeError(); | |
fn.__proto__ = AFunc.prototype | |
return fn | |
} | |
AFunc.prototype.__proto__ = Function.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
var actions = [ | |
function(next){ | |
setTimeout(function(){ | |
console.log(10) | |
next() | |
}, 1000) | |
console.log(1) | |
}, | |
function(next){ | |
setTimeout(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
Array.prototype.alternate = function(...arrs){ | |
var res = [] | |
arrs.unshift(this) | |
for(var i=0, precount=-1;precount!==(precount=res.length);i++){ | |
for(var j=0;j<arrs.length;j++){ | |
var arr = arrs[j] | |
i < arr.length && res.push(arr[i]) | |
} | |
} | |
return res |
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
<?php | |
require "lib.php"; | |
class EvE { | |
static $eve; | |
private $evs = []; | |
function on(...$args){ | |
overload($args, [ | |
[ | |
"type" => ["string", "function", "int"], |
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 promise(fn){ | |
var self = { | |
status: "pending", | |
value: undefined, | |
nexts: [], | |
__proto__: promise.prototype | |
} | |
function common(value, status){ | |
if(self.status !== "pending") return |
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 overload(args, fns){ | |
var result = null | |
fns.some(fn => { | |
if(Array.isArray(fn)){ | |
fn = {type: fn[0], function: fn[1]} | |
} | |
if(fn.type == null || fn.type.every((reqtype, i) => typeMatch(reqtype, args[i]))){ | |
result = fn.function(...args) | |
return true | |
} |
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
<?php | |
class Map{ | |
private $keys = []; | |
private $values = []; | |
function set($k, $v){ | |
$index = $this->getIndex($k); | |
if($index === false){ | |
$this->keys[] = $k; | |
$this->values[] = $v; |
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
<?php | |
class test{ | |
use Overload; | |
function test__num($a){ | |
return $a * $a; | |
} | |
function test__num2($a, $b){ | |
return $a + $b; |