Skip to content

Instantly share code, notes, and snippets.

@mugyu
Created August 17, 2012 17:14
Show Gist options
  • Save mugyu/3380723 to your computer and use it in GitHub Desktop.
Save mugyu/3380723 to your computer and use it in GitHub Desktop.
JavaScript の apply() の使い方メモ
fnc = function(str){console.log(this.name + ": " + str)};
obj = {name: "HOGE"};
arg = ["hi!"];
fnc.apply(obj, arg); // => HOGE: hi!
// fnc(arg) を obj に適用するって意味かなぁ
fnc.apply({name: "FOO"}, ["hello!"]); // => FOO: hello!
fnc.apply({name: "BAR"}, ["bood by!"]); // => BAR: bood by!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment