- From: Michael A. Puls II <shadow2531@gmail.com>
- Date: Wed, 23 Apr 2008 20:08:16 -0400
- To: "Boris Zbarsky" <bzbarsky@mit.edu>
- Cc: public-html@w3.org
- Message-ID: <6b9c91b20804231708o3b2946e8u62335ee218745f0a@mail.gmail.com>
On 4/23/08, Boris Zbarsky <bzbarsky@mit.edu> wrote: > Michael A. Puls II wrote: > > var obj = document.getElementById("test"); > > obj.type = "something"; > > obj.parentNode.replaceChild(obj.cloneNode(true), obj); > > > > , after doing the replacement, 'obj' would no longer point to the > > right object and I would have to manually update 'obj'. As an > > implementor, is it trivial for you to solve this problem *IF* it was > > necessary to go that route? > > > > I'm not quite sure what you're asking here. I'll clarify. Attached is reinit.html. The reinitialize prototype function is how I would solve the whole thing using just a little JS. The function clones the object, inserts the clone before the existing object, removes the existing object and returns a ref to the newly inserted object (or returns the existing object if it doesn't have a parentNode). The reason I do it that way is because it works really well. Since it's a whole new object getting inserted, the browser has no problem evaluating it. It works great in Opera, Firefox and Safari and this way, there's no need to type or data changes to cause a reinitialization. But, as you see, I need to do: obj = obj.reinitialize(); to update what 'obj' points to if I want to use 'obj' after reinitializing. What I was asking is, if you implemented a reinitialize() for OBJECT natively that did the clone, insert, remove deal just like I did, would you have any trouble making it so I wouldn't have to do: obj = obj.reinitialize() and instead could do just: obj.reinitialize(); and still make 'obj' point to the new object? In other words, if the reinitialize function() didn't return anything, would you be able to make it automatically update 'obj' internally? Or, would that not be possible? The reason I ask is, my reinitialize function works great and the idea might be worth considering, but it would be much better if the author didn't have to reassign 'obj' manually like that. Now, if you can get the same behavior without doing the clone + insert + replace and leave the obj ref in tact, I guess this doesn't matter. Thanks -- Michael
Attachments
- text/html attachment: reinit.html
Received on Thursday, 24 April 2008 00:08:52 UTC