Hi, T.J. Thank you for the explainnation. It's very clear.
best regards, Lin On Jul 17, 12:18 am, "T.J. Crowder" <[email protected]> wrote: > Hi Lin, > > this.initialize(arguments) would call the initialize method and pass > in an array of arguments as the first and only parameter to the > function. (Well, on many browsers 'arguments' isn't quite a real > array, but very similar to one.) this.initialize.apply(this, > arguments) calls the initialize method passing it the set of arguments > in the 'arguments' array as *individual* arguments. > > So: > > * * * * > > var a = [1, 2, 3]; > > this.function(a); > // => Passes the function a single argument that's an array, [1,2,3] > > this.function.apply(this, a); > // => Passes the function three individual arguments 1, 2, and 3 > > * * * * > > You have to use the second 'this' because the JavaScript apply > function requires the context (the value to use for "this" during the > call) as the first argument, and then the arguments array as the > second argument. (It needs this for a good reason -- it doesn't have > access to the value otherwise, because of the way "this" works in > JavaScript.) > > HTH, > -- > T.J. Crowder > tj / crowder software / com > Independent Software Engineer, consulting services available > > On Jul 16, 6:21 pm, damerub <[email protected]> wrote: > > > > > Could someone explain what the following line does? > > > this.initialize.apply(this, arguments); > > > I know how 'apply' works, but I cannot understand why 'this' is used > > twice here? both 'this' refer to the same object (current object). > > then why not just call this.initialize(arguments)?. What's the > > difference here? > > > THANKS IN ADVANCE! > > > Lin --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~----------~----~----~----~------~----~------~--~---
