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

Compiled Dart JS in combination with jQuery causes TypeError: Cannot call method 'apply' of undefined #2265

Closed
DartBot opened this issue Mar 23, 2012 · 19 comments

Comments

@DartBot
Copy link

DartBot commented Mar 23, 2012

This issue was originally filed by off...@mikemitterer.at


What steps will reproduce the problem?
1.
pull little sample app from git@github.com:MikeMitterer/SampleEventHandling.git
2.
Open the html-File with Fireforx or Chrom - not with Chromium
3.
Click on "Dart rocks" - works
Click on "JQuery rolls" - it fails
Open the Developer Tools in Chrome and you'll see the error message:
Uncaught TypeError: Cannot call method 'apply' of undefined

What is the expected output? What do you see instead?
It's expected that "Dart rocks" add a dot to the 17 and "JQuery rolls" should add
add a ~ to the numer but only the Dart-Part works.

What version of the product are you using? On what operating system?
Version 0.1.0.201203152021, Build 5549
Dart SDK version 5549, Dartium version
JQuery 1.7
MAC

Please provide any additional information below.
The currious thing it that it works in Chromium


Attachment:
screenshot-976.jpg (149.71 KB)

@anders-sandholm
Copy link
Contributor

Please unassign if this is not an IO lib issue. Possibly assign to Dart2JS then?


Added Area-UI, Triaged labels.

@DartBot
Copy link
Author

DartBot commented Mar 29, 2012

This comment was originally written by off...@mikemitterer.at


OK, you are right. It's probably Dart2JS. Are you forwarding this ticket to Dart2JS or do I have to do that?

@sethladd
Copy link
Contributor

sethladd commented Nov 8, 2012

I ran into this bug again trying to get js.dart + jQuery to work together: https://github.com/dart-lang/js-interop/issues/21

@vsmenon
Copy link
Member

vsmenon commented Nov 8, 2012

Refiled on dart2js. It appears that both dart2js generated code and jquery use a global '$' symbol in incompatible ways.


Removed Area-UI label.
Added Area-Dart2JS label.

@peter-ahe-google
Copy link
Contributor

cc @ErikCorryGoogle.
Added this to the Later milestone.

@peter-ahe-google
Copy link
Contributor

Issue #6853 has been merged into this issue.

@DartBot
Copy link
Author

DartBot commented Feb 17, 2013

This comment was originally written by shyc2...@gmail.com


I get both dart2js and jQuery working by calling jQuery.noConflict(). It releases the $ symbol which is causing the conflict.
Then I declare "var $ = jQuery;" as local variable, and the jQuery code after that works fine for me.

@DartBot
Copy link
Author

DartBot commented Apr 12, 2013

This comment was originally written by theme...@gmail.com


Will this issue be fixed in dart2js? It's annoying when use libraries depend on jQuery,
I cannot put "var $ = jQuery;" int libraries every time.

@kasperl
Copy link

kasperl commented May 23, 2013

Added TriageForM5 label.

@kasperl
Copy link

kasperl commented May 28, 2013

cc @peter-ahe-google.
Removed this from the Later milestone.
Added this to the M5 milestone.
Removed TriageForM5 label.

@peter-ahe-google
Copy link
Contributor

We should definitely try to avoid introducing global names.

For possible work arounds, take a look at: http://learn.jquery.com/using-jquery-core/avoid-conflicts-other-libraries/

Some of the techniques suggested in that document could also be used by dart2js.

@kasperl
Copy link

kasperl commented May 28, 2013

Removed this from the M5 milestone.
Added this to the Later milestone.

@peter-ahe-google
Copy link
Contributor

I needed to clean up how we access $ in some helper methods, so I added an option to control the name of $ to help me test it.

https://codereview.chromium.org/16135004 adds option --global-js-name to dart2js.


Added Started label.

@peter-ahe-google
Copy link
Contributor

Fixed in r23391.


Added Fixed label.

@DartBot
Copy link
Author

DartBot commented Jun 11, 2013

This comment was originally written by kholbr...@sonardesign.com


This is still a problem with the build from 23799.
Is is fixed to not abuse "$" or just to have the work-around flag?
This is a serious problem, please fix correctly by not abusing "$".

@peter-ahe-google
Copy link
Contributor

kholbrook, what is, in your opinion, a correct fix?

@DartBot
Copy link
Author

DartBot commented Jun 11, 2013

This comment was originally written by kholbr...@sonardesign.com


Do not abuse "$".
There is no reason to obliterate "$", which is the most widely used mechanism for javascript libraries to add extensions on the planet. Seriously.
Developers world-wide use jQuery, which everyone knows uses "$".
There is no reason dart2js can not put the generated code in a global with a name specific to Dart. This is exactly what we are all forced to do to make it work. Forcing a default that causes serious compatibility problems is not the correct approach. Not to mention being forced to use the work-around flag means you are forced out of the editor and having to use the command-line to invoke dart2js, since the editor does not support options for dart2js invocation. This breaks workflow, this breaks compatibility. This is just plain wrong.

@peter-ahe-google
Copy link
Contributor

Ideally, dart2js should generate code wrapped in something like this:

!function($) {
...
}({})

Unfortunately, we discovered that this had an adverse effect on performance. Fortunately, the V8 team has since been working on fixing this issue, and we hope to be able to completely eliminate the use of global variables.

For now, offering an option is the best we can do.

@DartBot
Copy link
Author

DartBot commented Jun 12, 2013

This comment was originally written by kholbr...@sonardesign.com


In the interim, would it be possible to make the default "$dart"?

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

No branches or pull requests

6 participants