Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Closed
DartBot opened this Issue · 19 comments

6 participants

@DartBot
Collaborator

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

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


Added Area-UI, Triaged labels.

@DartBot
Collaborator

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
Owner

I ran into this bug again trying to get js.dart + jQuery to work together: dart-lang/js-interop-experimental#21

@vsmenon
Collaborator

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
Collaborator

cc @ErikCorryGoogle.
Added this to the Later milestone.

@peter-ahe-google
Collaborator

Issue #6853 has been merged into this issue.

@DartBot
Collaborator

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
Collaborator

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
Collaborator

Added TriageForM5 label.

@kasperl
Collaborator

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

@peter-ahe-google
Collaborator

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
Collaborator

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

@peter-ahe-google
Collaborator

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
Collaborator

Fixed in r23391.


Added Fixed label.

@DartBot
Collaborator

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
Collaborator

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

@DartBot
Collaborator

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
Collaborator

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
Collaborator

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


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

@DartBot DartBot added this to the Later milestone
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.