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
documentReady() | |
.then(loopDfd([initXxxDB, xxxDBReady], xxxDBError)) | |
.then(xxxTask) | |
.fail(uncaughtError); | |
// deferredがresolveされるまで、restartCallbackを挟みながら処理を繰り返すメソッド。 | |
// 第一引数には配列もしくは配列を返す関数を渡すことが出来る。 | |
function loopDfd(actorDfdList, restartCallback){ | |
if(typeof(actorDfdList) === "function") actorDfdList = actorDfdList(); | |
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 strict'; | |
/** | |
* 画像を非同期で読み込む関数 | |
* @param {string} source - 画像URL | |
* @return {Promise} Imageをthenコールバックの第1引数として渡すPromise | |
*/ | |
function loadImageAsync(source) | |
{ | |
return new Promise((resolve, reject) => { |
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 consume(reader, length) { | |
var total = 0; | |
return (function pump() { | |
console.log(`${total} / ${length}`); | |
return reader.read().then(function(args) { | |
if (!args.done) { | |
total += args.value.byteLength; | |
return pump(); | |
} |
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 strict"; | |
const resolverSymbol = Symbol("resolver"); | |
const notifierListSymbol = Symbol("notifierList"); | |
const cancelSymbol = Symbol("cancel"); | |
class Gaobservable{ | |
constructor(resolver){ | |
if(typeof(resolver) !== "function") throw new TypeError(`Gaobservable resolver ${resolver} is not a 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
const queue = Symbol("queue"); | |
const sync = Symbol("sync"); | |
const createAwaiter = Symbol("createAwaiter"); | |
const addQueue = Symbol("addQueue"); | |
const syncMethods = Symbol("syncMethods"); | |
const Awaiter = ((Base)=> { | |
class Awaiter extends Base{ | |
constructor(...args){ | |
super(...args); |
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
class Human{ | |
constructor(name, age){ | |
this.name = name; | |
this.age = age; | |
} | |
static clone(obj){ return new this(obj.name, obj.age); } | |
} | |
class Woman extends Human{} |
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 stableSort(arr, callback){ | |
var indexMap = new Map(null); | |
for(var i=0;i<arr.length;i++){ | |
indexMap.set(arr[i], i); | |
} | |
var result; | |
arr.sort(function compare(a, b){ | |
result = (callback) ? callback(a, b) : false; |
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
//RGBの情報から、HSVの情報を得る汎用メソッド | |
//「http://p.tl/YDI3」のJavaソースコードをJSに移植しただけです。 | |
function GetHSVColorByRGBColor(rgb){ | |
var hue,saturation,value; | |
var max = Math.max(rgb.r,rgb.g,rgb.b); | |
var min = Math.min(rgb.r,rgb.g,rgb.b); | |
//hue | |
if(max == min){ | |
hue = 0; |
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
const drawHueCircle = Symbol("drawHueCircle"); | |
const drawSVRect = Symbol("drawSVRect"); | |
Object.defineProperties(CanvasRenderingContext2D.prototype, { | |
[drawHueCircle]: { | |
value(x, y, rIn, rOut, splitNum=180){ | |
// 描画半径を計算で求める | |
const r = 2 * rOut; | |
// 直前のスタイル情報のバックアップ | |
const oldStrokeStyle = this.strokeStyle; |
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 milkbox(uri){ | |
// 文字列としてエレメントを定義 | |
var eleStr = function(){/* | |
<div id="milkbox_body" class="milk_wrap"> | |
<div class="milkbox_container"> | |
<div class="milkbox_content"> | |
<img src="CONTENT_URI"> | |
<div class="milkbox_button">x</div> | |
<div id="loader_id" class="loader"> | |
<img src="img/load.gif"> |