Last active
August 29, 2015 14:18
-
-
Save greggman/15b5285fab6e0ca0a799 to your computer and use it in GitHub Desktop.
Revisions
-
greggman revised this gist
Apr 7, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -24,7 +24,7 @@ The same would be true of adding properties to elements. If you've got code like function makeDivWithProperities(parent) { var div = document.createElement("div"); parent.appendChild(div); div.deviceWidth = someMagicFunctionToComputeDeviceWidth(div); // !!! } If tomorrow some standard decides to add `deviceWidth` to all HTMLElements than any app using that name will break. -
greggman revised this gist
Apr 7, 2015 . 1 changed file with 14 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,9 +13,21 @@ get added to the window object. I can't believe I've been programming web stuff But.... The bigger issue is this seems like a timebomb waiting to happen. The problem is you write some code today. Let's say you write "use strict"; var numProcessesAvailable = 100; // Some application specific variable. Tomorrow some new web standard comes out and decides there should be a variable on window called `numProcessesAvailable`. At that point every program what was using a variable in the global scope called `numProcessesAvailable` breaks. The same would be true of adding properties to elements. If you've got code like this "use strict" function makeDivWithProperities(parent) { var div = document.createElement("div"); parent.appendChild(div); div.deviceWidth = div.clientWidth * window.devicePixelRatio; // Scary! } If tomorrow some standard decides to add `deviceWidth` to all HTMLElements than any app using that name will break. Can that really be what Firefox wants? Is there an issue filed about this somewhere? I'd like to read the thinking on this issue. It seems like it has to be the Chrome way otherwise every time a new property is added to any native browser object and you're running in strict mode you run the risk of breaking lots of web pages. -
greggman revised this gist
Apr 7, 2015 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,8 +12,8 @@ get added to the window object. I can't believe I've been programming web stuff But.... The bigger issue is this seems like a timebomb waiting to happen. The problem is you write some code today. Let's say you write "use strict"; var cameraResolution = 1000; Tomorrow some new web standard comes out and decides there should be a variable on window called `cameraResolution`. At that point every program what was using a variable in the global scope called `cameraResolution` breaks. -
greggman created this gist
Apr 7, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ So I had a sample that wasn't working in firefox. It had code like ths "use strict"; var devicePixelRation = window.devicePixelRatio || 1; That worked fine on Chrome but broke on Firefox with TypeError: setting a property that has only a getter So first thing I learned something I didn't know. Variables declared **with** `var` in the global scope get added to the window object. I can't believe I've been programming web stuff for like forever and even was on the Chrome team for 5 years and didn't know this. I new variables without `var` were added to the window but I didn't know globals **with** `var` were added. They aren't added to other objects in other scopes. I'm going to have to assume this is some legacy issue they can't get rid of But.... The bigger issue is this seems like a timebomb waiting to happen. The problem is you write some code today. Let's say you write "use strict"; var cameraResolution = 1000; Tomorrow some new web standard comes out and decides there should be a variable on window called `cameraResolution`. At that point every program what was using a variable in the global scope called `cameraResolution` breaks. Can that really be what Firefox wants? Is there an issue filed about this somewhere? I'd like to read the thinking on this issue. It seems like it has to be the Chrome way otherwise every time a new property is added to any native browser object and you're running in strict mode you run the risk of breaking lots of web pages. No? Thoughts?