Created
August 31, 2011 10:16
-
-
Save ishiduca/1183239 to your computer and use it in GitHub Desktop.
移譲を使う(いい例じゃない)
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 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