Skip to content

Instantly share code, notes, and snippets.

@susisu
Last active August 29, 2015 14:10
Show Gist options
  • Save susisu/76c43af9b5771ecb2465 to your computer and use it in GitHub Desktop.
Save susisu/76c43af9b5771ecb2465 to your computer and use it in GitHub Desktop.
[[Construct]]
// 注意: アロー関数を排除できない
function ctor (Ctor) {
return function () {
if(typeof Ctor !== "function") {
throw new TypeError(typeof Ctor + " is not a function");
}
var proto = Ctor.prototype;
if (proto === null || typeof proto !== "object") {
proto = Object.prototype;
}
var obj = Object.create(proto);
var result = Ctor.apply(obj, arguments);
if (result === null || typeof result !== "object") {
return obj;
}
else {
return result;
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment