Skip to content

Instantly share code, notes, and snippets.

@hell0again
Last active August 29, 2015 14:05
Show Gist options
  • Save hell0again/745d904c48522c6adf44 to your computer and use it in GitHub Desktop.
Save hell0again/745d904c48522c6adf44 to your computer and use it in GitHub Desktop.
Promise.deferを書いてたときにcoffeeの変数宣言で泣いた
# Promise.deferが欲しかったので適当に書いてみる
# @deferの先頭でresolve, rejectの変数宣言をしたかった
# we want Promise.defer!!
`if (typeof define !== 'function') { var define = require('amdefine')(module) } // for node`
define [
'es6-promise'
], (es6Promise) ->
'use strict'
class Promise extends es6Promise.Promise
@defer: () ->
resolve
reject
promise = new es6Promise.Promise (res, rej) ->
resolve = res
reject = rej
return
{
promise: promise
resolve: resolve
reject: reject
}
// Generated by CoffeeScript 1.7.1
(function() {
if (typeof define !== 'function') { var define = require('amdefine')(module) } // for node;
var __hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
define(['es6-promise'], function(es6Promise) {
'use strict';
var Promise;
return Promise = (function(_super) {
__extends(Promise, _super);
function Promise() {
return Promise.__super__.constructor.apply(this, arguments);
}
Promise.defer = function() {
resolve;
reject;
var promise;
promise = new es6Promise.Promise(function(res, rej) {
var reject, resolve;
resolve = res;
reject = rej;
});
return {
promise: promise,
resolve: resolve,
reject: reject
};
};
return Promise;
})(es6Promise.Promise);
});
}).call(this);
# defer先頭で適当に代入する形
# we want Promise.defer!!
`if (typeof define !== 'function') { var define = require('amdefine')(module) } // for node`
define [
'es6-promise'
], (es6Promise.Promise) ->
'use strict'
class Promise extends es6Promise.Promise
@defer: () ->
resolve = 'yadayada'
reject = 'yadayada'
promise = new es6Promise.Promise (res, rej) ->
resolve = res
reject = rej
return
{
promise: promise
resolve: resolve
reject: reject
}
// Generated by CoffeeScript 1.7.1
(function() {
if (typeof define !== 'function') { var define = require('amdefine')(module) } // for node;
var __hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
define(['es6-promise'], function(es6Promise) {
'use strict';
var Promise;
return Promise = (function(_super) {
__extends(Promise, _super);
function Promise() {
return Promise.__super__.constructor.apply(this, arguments);
}
Promise.defer = function() {
var promise, reject, resolve;
resolve = 'yadayada';
reject = 'yadayada';
promise = new es6Promise.Promise(function(res, rej) {
resolve = res;
reject = rej;
});
return {
promise: promise,
resolve: resolve,
reject: reject
};
};
return Promise;
})(es6Promise.Promise);
});
}).call(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment