Skip to content
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

ES5 bug related with constructor call without new keyword #866

Closed
dawiidio opened this issue Jun 9, 2018 · 3 comments
Closed

ES5 bug related with constructor call without new keyword #866

dawiidio opened this issue Jun 9, 2018 · 3 comments

Comments

@dawiidio
Copy link

dawiidio commented Jun 9, 2018

When try to use svg.js in my lib with es5 modules and webpack@4.x + babel@6.2.x I found bug related with new ECMAscript 262 feature, I mean the one that says about calling constructor function without new keyword. Before, when you have been calling function without new, this reference the global object (window in a browser), from now in this case this is set to undefined to prevent accidental littering window object.

Previous functionality has been used in svg.js file, here

// The main wrapping element
var SVG = this.SVG = function(element) { // here - `this` no longer will be referenced to window
  if (SVG.supported) {
    element = new SVG.Doc(element)

    if(!SVG.parser.draw)
      SVG.prepare()

    return element
  }
}

My suggest is a change from this.SVG to window.SVG because when module is wrapped into umd.js already gets prepared window object from parent function.

I can handle this today, in hour or two I'll create MR with proposed changes :)

@Fuzzyma
Copy link
Member

Fuzzyma commented Jun 10, 2018

At the very end of svg.js there is a return SVG which automatically binds SVG to the window object. But this and window can be different. Thats why it was like it is because it led to trouble when including plugins (yes we wanted to litter the global object because plugin relied on it). However since these restrictions are there and will not go away we need to fix that somehow.

One way is to add an UMD wrapper to ALL plugins (phew...). The other would be to wait for 3.0 to get released. Actually I would prefer the second one.

What do you think?

@dawiidio
Copy link
Author

Ok, for my lib purposes I can use version from branch on forked version until the 3.0 version will be released

@saivan
Copy link
Member

saivan commented Dec 2, 2018

3.0 is out. It should have your problem fixed, but if not; just continue the chat here :) I'll close for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants