As I understand it, the new operator creates an empty object, sets the prototype field, then calls the constructor. However, functions from the prototype do not show up in autocomplete or the details sidebar when the debugger pauses within a constructor. Test case: Foo = new function() { this._luckyNumber = 3; debugger; } Foo.prototype = { get luck() { return this._luckyNumber; }, set luck(v) { this._luckyNumber = v; }, toString: function() { return "" + this._luckyNumber; } } var f = new Foo(); f.luck = 4; f.luck; f.toString();
> Foo = new function() { > this._luckyNumber = 3; > debugger; > } > > [snip] > > var f = new Foo(); As written, this causes an exception. Since you are doing "Foo = new function" up above and then "new Foo". [Error] TypeError: Object is not a constructor (evaluating 'new Foo()') Things behave as expected when you create the constructor: function Foo() { this._luckyNumber = 3; debugger; } Is there still an issue here?
(In reply to comment #0) > As I understand it, the new operator creates an empty object, sets the > prototype field, then calls the constructor. However, functions from the > prototype do not show up in autocomplete or the details sidebar when the > debugger pauses within a constructor. > > Test case: > > Foo = new function() { > this._luckyNumber = 3; > debugger; > } > > Foo.prototype = { > get luck() { return this._luckyNumber; }, > set luck(v) { this._luckyNumber = v; }, > toString: function() { return "" + this._luckyNumber; } > } Also, as written the debugger pauses inside the "new function" without having assigned the prototype yet. So the debugger was behaving correctly then.
Created attachment 243313 [details] Better test case
The test case behaves as expected right now, but can be improved. The console autocompletes prototype properties, and expanding this -> proto -> you see luck getter / setters. We are looking to improve the object display (Object Properties tree) in: <https://webkit.org/b/137306> Web Inspector: Expanding event objects in console shows undefined for most values, it should have real values Specifically: https://bugs.webkit.org/show_bug.cgi?id=137306#c3 Lets dup? *** This bug has been marked as a duplicate of bug 137306 ***