theFunction.call(objOfThis, arg1, arg2, ...)
apply :
theFunction.apply(objOfThis, arrayOfArgs)
# objOfThis(接收者)如果沒提供參數, 則 global 就會被當成接收者
function theFunction(name, profession) { console.log("My name is " + name + " and I am a " + profession + "."); } theFunction("Ian", "programmer"); theFunction.apply(undefined, ["Terry", "dancer"]); theFunction.call(undefined, "Peter", "writer");
顯示 :
沒有留言:
張貼留言