Skip to content

Instantly share code, notes, and snippets.

@ishiduca
Created August 31, 2011 10:16
Show Gist options
  • Save ishiduca/1183239 to your computer and use it in GitHub Desktop.
Save ishiduca/1183239 to your computer and use it in GitHub Desktop.
移譲を使う(いい例じゃない)
var t1, add;
t1 = function () {
var Hold = function (_num) {
this.num = _num;
this.add = function (num2) {
return toNumber(this.num) + toNumber(num2);
};
};
var hold = new Hold (3);
test(hold.add(4), 7);
add = function (_num, num2) {
return hold.add.apply({ num : _num }, [ num2 ]);
};
};
t1();
test(add(8, 9), 17);
/* Functions */
function test (res_func, res) {
var is_success = (res_func === res) ? 'success:' : '! faild:';
console.log([is_success,res_func, res].join(" "));
}
function toNumber (n) {
return (typeof n === 'number') ? n
: (Number(n)) ? Number(n)
: 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment