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

DartBot opened this Issue Mar 23, 2012 · 19 comments


None yet

6 participants

DartBot commented Mar 23, 2012

This issue was originally filed by

What steps will reproduce the problem?
pull little sample app from
Open the html-File with Fireforx or Chrom - not with Chromium
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, Build 5549
Dart SDK version 5549, Dartium version
JQuery 1.7

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

screenshot-976.jpg (149.71 KB)


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

Added Area-UI, Triaged labels.

DartBot commented Mar 29, 2012

This comment was originally written by

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

sethladd commented Nov 8, 2012

I ran into this bug again trying to get js.dart + jQuery to work together:

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.


cc @ErikCorryGoogle.
Added this to the Later milestone.


Issue #6853 has been merged into this issue.

DartBot commented Feb 17, 2013

This comment was originally written by

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 commented Apr 12, 2013

This comment was originally written by

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 commented May 23, 2013

Added TriageForM5 label.

kasperl commented May 28, 2013

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


We should definitely try to avoid introducing global names.

For possible work arounds, take a look at:

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

kasperl commented May 28, 2013

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


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. adds option --global-js-name to dart2js.

Added Started label.


Fixed in r23391.

Added Fixed label.

DartBot commented Jun 11, 2013

This comment was originally written by

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 "$".


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

DartBot commented Jun 11, 2013

This comment was originally written by

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.


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 commented Jun 12, 2013

This comment was originally written by

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

@DartBot DartBot added this to the Later milestone Jun 12, 2013
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment