欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
Quick Tip: Calling JavaScript Methods on Other Objects

Using Call and Apply

Here’s the scenario: we have two objects:

  1. var joe = {  
  2.     name : "Joe",  
  3.     greet : function (name) {  
  4.         alert(this.name + " says hello to " + name);  
  5.     }  
  6. };  
  7.   
  8. var jill = {  
  9.     name : "Jill"  
  10. };  

It’s pretty simple to get Joe to greet Jill:

  1. joe.greet("Jill");  

But how can we get Jill to greet Joe? She doesn’t have a greet method (and let’s assume we can’t / won’t / shouldn’t give her one). Well, because everything in JavaScript—including functions—is an object, everything can have a method, or a function that can be called from it. Functions are given two methods that allow you to call them in different contexts.

The context of a method is basically the object that will be this when the function is called. In our greetmethod, this refers to the object joe, because that’s what it is a part of.

Now, try this:

  1. joe.greet.call(jill, "Joe");  

The call method on JavaScript functions allows you to change the function’s context. The first parameter we pass in will be the new context: in this case, that’s jill. Subsequent parameters are the parameters to the function you’re calling. In this case, “Joe” will be passed to greet. If you run this, you’ll get an alert box with the message “Jill says hi to Joe.”

There’s also an apply method; the only difference is that it takes the parameters of the method as an array, rather than as raw parameters, a la the call method.

  1. joe.greet.call(jill, ["Joe"]);  

If you have a hard time remembering whether it’s call or apply that takes the array, remember that applyand array both start with ”a.”

Thanks for reading!

本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
Android自動(dòng)化測試之MonkeyRunner
24 ways: Easy Ajax with Prototype
Scala 學(xué)習筆記(一)
如何從 ASP 調用 SQL Server 存儲過(guò)程
What's up with BeginInvoke? - starspace - 博客園
Android:線(xiàn)程的結束,掛起和恢復(下)
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久