Skip to content

new js interop, problem with this in method calling #24747

@kasperpeulen

Description

@kasperpeulen

I have the following code:

@JS('MathJax.Hub')
external get MathJaxHub;

@JS('MathJax.Hub.Queue')
external Function get MathJaxHubQueue;

void main() {
  new Future.delayed(const Duration(seconds: 3), () {
    querySelector('body').text = r"\(1+1 = 2\)";

    context['MathJax']['Hub'].callMethod('Queue', [["Typeset", MathJaxHub]]);

    MathJaxHubQueue(['Typeset', MathJaxHub]);
  });
}

I can give a more complete example, if you guys want to reproduce this. But basically, I would expect that:

context['MathJax']['Hub'].callMethod('Queue', [["Typeset", MathJaxHub]]);

is equivalent with:

MathJaxHubQueue(['Typeset', MathJaxHub]);

But they don't act the same. After some debugging I found out that on the JS side, the this in the function:

MathJax.Hub = {
  Queue: function () {
    return this.queue.Push.apply(this.queue,arguments);
  },

is in the first one captured as MathJax.Hub but in the second the this variable will be equal to window.

Is there something I do wrong, or is this a bug?

Metadata

Metadata

Assignees

Labels

web-js-interopIssues that impact all js interop

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions