以下參考TS和JS互相調(diào)用(不用什么靜態(tài)方法)
JS:<script>
function jsFun(a){
return a;
}
</script>
TS:
class ImTS{
function tsFun(a):any{
return a;
}
}
var imTS:ImTS = new ImTS();
window['imTS'] = imTS; //這步不能少
JS調(diào)用TS:
<script>
window.imTS.tsFun();
</script>
TS調(diào)用JS:
window['jsFun']();
以下參考關(guān)于js 調(diào)用 ts 的問題,在線等
module game {
/**
*
* @author zhy
*
*/
export class TClass {
private static s_instance: TClass = null;
private platformInstance: TClass;
public static getInstance(): TClass {
if(!TClass.s_instance) {
TClass.s_instance = new TClass();
TClass.s_instance.init();
}
return TClass.s_instance;
}
public constructor() {
if(TClass.s_instance) {
throw new egret.error("TClass is a singleton class.");
}
this.init();
}
private init(){
window['platformInstance'] = TClass.s_instance;
}
public jsCallFun(_arg:string):void{
console.log(_arg);
}
}
}
js:
window.platformInstance.jsCallFun("test!");
Ts中: window['platformInstance'] = TClass.s_instance; 注意一定要的。
在index的script里面寫js函數(shù)和變量
ts調(diào)用參數(shù)是就是 window["參數(shù)名"],函數(shù)是window["函數(shù)名"]