-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Binding context exports unnecessary properties which could shadow globals. #2294
Comments
Those are good points. Perhaps we shouldn't minify |
Not minifying |
We could use a |
It is possible for properties such as `_subscribable` to be created on a binding context, which, after minification, could be renamed to any arbitrary character. In most cases this is not an issue, except when a global variable with the same name exists, however rare the case may be. This causes the global variable to be shadowed in all bindings, which is especially problematic in the case of, say, `$`, which breaks jquery. To fix this, either hide such properties with a Symbol, or simply don't minify them so that the name is constant and predictable. Fixes knockout#2294
It is possible for properties such as `_subscribable` to be created on a binding context, which, after minification, could be renamed to any arbitrary character. In most cases this is not an issue, except when a global variable with the same name exists, however rare the case may be. This causes the global variable to be shadowed in all bindings, which is especially problematic in the case of, say, `$`, which breaks jquery. To fix this, either hide such properties with a Symbol, or simply don't minify them so that the name is constant and predictable. Fixes knockout#2294
In the file bindingAttributeSyntax.js a
_subscribable
property is created on a binding context under certain conditions. During build, this property is minified and in the 3.4.2 release it is exported asQ
. See this jsfiddle for an example: https://jsfiddle.net/s0wf1hga/1/. Note the errors in console.This becomes a problem when a global property with the same name exists and referenced from inside bindings. Granted, the chance of a name conflict is rare. I did, however, encounter a problem with a custom build I was making where
_subscribable
was minified to$
, which shadowed jquery in all bindings and broke a lot of things.The workarounds for this problem are many, I know, but rather than a workaround I feel it is more right and rather easy to remove the problem. I'm also not saying that all unnecessary properties everywhere should be hidden, but the binding context is a rather unique situation with more ramifications than usual.
The text was updated successfully, but these errors were encountered: