NEW 201695
Function declaration statements in false conditional contexts create working functions and assign them to identifiers in the parent context.
https://bugs.webkit.org/show_bug.cgi?id=201695
Summary Function declaration statements in false conditional contexts create working ...
Dave Livesay
Reported 2019-09-11 13:33:59 PDT
The following statement if (false) { function myFunction(){ return "I work!"; } } should declare a variable, "myFunction," in the parent namespace, if it doesn't already exist, but it should neither assign a value to the variable nor create a function. This behavior is confirmed, for example, in the Google Chrome console: > if(false){function myFunction(){return "I work!";}} < undefined > "myFunction" in window < true > typeof myFunction < "undefined" And attempting to invoke myFunction throws a TypeError error. In the Safari console, however, a working function is created and assigned to the variable: > if(false){function myFunction(){return "I work!";}} < undefined > "myFunction" in window < true > typeof myFunction < "function" > myFunction() < "I work!" The behavior is the same if the variable already exists and has a value in the parent namespace: > myFunction = "just a string" < "just a string" > typeof myFunction < "string" > if(false){function myFunction(){return "I work!";}} < undefined > typeof myFunction < "function" Thus, the existing value is overwritten with the function.
Attachments
Radar WebKit Bug Importer
Comment 1 2019-09-13 20:23:06 PDT
Note You need to log in before you can comment on or make changes to this bug.