Hi again, The problem isn't resolving the write function - that works in both cases. The only difference is the binding of 'this' inside the write function. It sounds like you're saying that the document.write function in Google Chrome doesn't like it when 'this' is bound to the window object (and not the document object) whereas the equivalent function in Microsoft Internet Explorer tolerates it.
Cheers, Kasper On Sat, Jan 23, 2010 at 3:43 PM, Xiang Zhong <[email protected]> wrote: > Hi, Kasper, > > But something is still not clear > 1. For the two samples, they have similar form(for the 1st sample, take > "document" as "object", and "write" a method under "object") > var alias = object.fun; > alias("something"); > If "write" can't get resolved under global scope in the 1st sample, then why > should "foo" can be resolved for 2nd sample? Since they are so alike to each > other. > 2. Sample 1 can be executed on IE, but it can't get runned on chrome. Which > one is standard conformance? > > Cheers > Xiang > > 2010/1/23 Kasper Lund <[email protected]> >> >> Hi Xiang, >> >> I haven't looked closely at this issue, but if I had to guess I would >> attribute the difference to the fact that 'this' is bound differently >> in the call to write in the two cases. In the first case, 'this' will >> be the global object - that is the window object not the document - >> and in the second case 'this' will be the document. >> >> Cheers, >> Kasper >> >> On Sat, Jan 23, 2010 at 5:09 AM, Xiang Zhong <[email protected]> wrote: >> > Hi, friends, >> > I got an interesting question here >> > Script like this can't be executed, it will throw a exception invocation >> > error. >> > <script> >> > var alias = document.write; >> > alias("something"); >> > </script> >> > >> > >> > But if we define the script like the following, then it is OK for >> > excution. >> > >> > <script> >> > function constructor(){}; >> > var object = new constructor(); >> > object.fun = function (str){document.write(str);} >> > >> > var alias = object.fun; >> > alias("something"); >> > </script> >> > >> > Why these two behavior differently? >> > What is the reason? >> > >> > Cheers~ >> > Xiang >> > >> > -- >> > v8-users mailing list >> > [email protected] >> > http://groups.google.com/group/v8-users >> >> -- >> v8-users mailing list >> [email protected] >> http://groups.google.com/group/v8-users > > -- > v8-users mailing list > [email protected] > http://groups.google.com/group/v8-users -- v8-users mailing list [email protected] http://groups.google.com/group/v8-users
