Bug 16121

Summary: Web Inspector needs helper functions that pass a 'this' object to addEventListener and setTimeout
Product: WebKit Reporter: Timothy Hatcher <timothy>
Component: Web Inspector (Deprecated)Assignee: Timothy Hatcher <timothy>
Status: RESOLVED FIXED    
Severity: Enhancement    
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: All   
OS: All   
Attachments:
Description Flags
Patch
none
Revised Patch aroben: review+

Timothy Hatcher
Reported 2007-11-24 12:55:26 PST
The Web Inspector code is very object oriented and it needs to add event listeners and timeouts that call object functions with a correct 'this' object. A common practice sprinkles throughout the code is: var _self = this; setTimeout(function() { _self.foo() }, 0); node.addEventListener('bar', function() { _self.bar() }, false); We should add helper functions that simplify this.
Attachments
Patch (23.92 KB, patch)
2007-11-24 13:04 PST, Timothy Hatcher
no flags
Revised Patch (22.91 KB, patch)
2007-11-24 14:27 PST, Timothy Hatcher
aroben: review+
Timothy Hatcher
Comment 1 2007-11-24 13:04:59 PST
Adam Roben (:aroben)
Comment 2 2007-11-24 13:18:24 PST
Comment on attachment 17487 [details] Patch I was thinking about fixing this as well, but in a slightly different way. I was going to add a new function: Function.bind = function(func, thisObject) { return function() { func.call(thisObject) } } Then you could do things like: setTimeout(Function.bind(this.updateTitle, this), 0); What do you think about that solution? I like that it's very general and so can be used in more places.
Adam Roben (:aroben)
Comment 3 2007-11-24 13:19:24 PST
(In reply to comment #2) > Function.bind = function(func, thisObject) { > return function() { func.call(thisObject) } > } You'd want to pass arguments through, as well.
Timothy Hatcher
Comment 4 2007-11-24 13:33:12 PST
Comment on attachment 17487 [details] Patch I am going to redo this based on Adam's comment.
Timothy Hatcher
Comment 5 2007-11-24 14:27:21 PST
Created attachment 17488 [details] Revised Patch
Adam Roben (:aroben)
Comment 6 2007-11-24 14:34:19 PST
Comment on attachment 17488 [details] Revised Patch I think "toggleExpanded" would be clearer than just "toggle" for the two places you added that function. I don't think the order of the <script> elements matters, since none of this code gets executed as it's parsed. r=me
Timothy Hatcher
Comment 7 2007-11-24 14:36:20 PST
Note You need to log in before you can comment on or make changes to this bug.