joint icon indicating copy to clipboard operation
joint copied to clipboard

Uncaught TypeError: Object [object global] has no method '_prepareData'

Open norm2782 opened this issue 13 years ago • 3 comments

When using joint.layout.DirectedGraph, I get the following error on line 20574 of joint.all.js (in both the latest release and the latest git version of the file):

Uncaught TypeError: Object [object global] has no method '_prepareData'

This is due to the fact that "this" seems to be pointing to Window, rather than the joint.layout.DirectedGraph object.

_prepareData could easily be inlined to solve this problem and the resulting code would still be readable.

norm2782 avatar Oct 09 '13 07:10 norm2782

There is no need to inline the _prepareDate() function. How exactly are you calling the layout() method? This seems like it is called with a wrong context.

DavidDurman avatar Oct 15 '13 12:10 DavidDurman

I'm calling window.joint.layout.DirectedGraph.layout(graph, args) The context is somewhat more complex than usual. We're compiling Clean [1] down to JS and we can interact with existing JS libraries, so we're calling the above from within our custom runtime system.

[1] http://wiki.clean.cs.ru.nl/Clean

norm2782 avatar Oct 18 '13 11:10 norm2782

To give you an impression, below is a snippet of generated code where layout is called:

function __pref_layoutGraph(__g_0, __world_1) {
    var ___x_1_0_1 = [__pref_jsEmptyObject, [__world_1]],
        __obj_1_1_1 = [___predefined_tupsels2v0, [___x_1_0_1]];
    return ___predefined_tupsels2v1([__pref_callFunction$eval, [\"joint.layout.DirectedGraph.layout\",[0,___predefined__Cons$n,[__pref_toJSArg,[__g_0]],[0,___predefined__Cons$n,[__pref_toJSArg,[__obj_1_1_1]]

As you can see "joint.layout.DirectedGraph.layout" is passed as a string and is evaluated later in __pref_callFunction$eval.

My previous comment still holds to an extent, but there is a lot more bookkeeping code around it that probably gets in the way first.

While I recognise that this is probably not the first use case you had in mind when writing JointJS, it does highlight that JointJS is sensitive to JavaScript's dynamic scope for the "this" keyword, which currently limits the use cases for JointJS. We haven't run into this particular problem with jQuery and the Google Maps API, which suggests that it is possible for libraries to exercise more control over the scope of "this".

norm2782 avatar Nov 04 '13 09:11 norm2782