Posted By

eryoav on 09/18/11


Tagged

javascript


Versions (?)

apply()


 / Published in: JavaScript
 

URL: http://jsfiddle.net/nzPw2/

simple example for implementing apply method.

  1. x = 10;
  2. var obj = {x:0}
  3.  
  4. function func1(msg) {
  5. alert(this.x + " " + msg)
  6. }
  7.  
  8. function func2(msg1, msg2) {
  9. alert(this.x + " " + msg1 + " " + msg2)
  10. }
  11.  
  12. function main(o, fn, arrMsg) {
  13. fn.apply(o, arrMsg)
  14. }
  15.  
  16. main(obj, func1, ["test"]);
  17. main(obj, func2, ["test1", "test2"]);

Report this snippet  

You need to login to post a comment.