2014-02-21 3 views
5

Javascript에서 다트 함수를 호출하고 싶습니다.Javascript에서 다트 함수를 호출하는 방법은 무엇입니까?

나는 dart2js (버전 1.1.3)을 사용하여 다트 함수를 포함하는 다트 스크립트를 컴파일 한 다음 생성 된 .js 파일을 자바 환경에로드하고이 함수를 자바 스크립트에서 호출하려고합니다.

Javascript의 myHyperSuperMegaFunction을 (를) 호출하는 행에 뭔가가 있습니다.

import 'dart:js' as js; 

int myHyperSuperMegaFunction(int a, int b) { 
    return a + b; 
} 

main() { 
    js.context['myHyperSuperMegaFunction'] = new js.JsFunction.withThis(myHyperSuperMegaFunction); 
} 

나는 dart2js와 위를 컴파일하고 크롬으로 생성 된 .js 파일을로드했습니다. 변수 myHyperSuperMegaFunction 등록 내가 크롬 자바 스크립트 콘솔에서 myHyperSuperMegaFunction(2,3)를 호출 할 때 나는 new js.JsFunction.withThis을 사용하려면 필요하지 않은 다음과 같은 오류 NoSuchMethodError : method not found: 'Symbol("call")' Receiver: Instance of '(){this.$initialize' Arguments: [Instance of 'Window', 2, 3]

답변

5

를 얻을

그러나
function() { 
    return _call(f, captureThis, this, Array.prototype.slice.apply(arguments)); 
} 

으로 정의된다. 귀하의 경우에는 바로 사용 : 당신이 this JS 컨텍스트를 사용해야하는 경우에 귀하의 정보 new js.JsFunction.withThis를 들어

js.context['myHyperSuperMegaFunction'] = myHyperSuperMegaFunction; 

이 사용되어야한다. 오류에서 첫 번째 매개 변수는 Js의 글로벌 컨텍스트 인 Instance of 'Window'이라는 것을 알 수 있습니다.

관련 문제