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调用TS:
<script>
window.imTS.tsFun();
</script>
TS调用JS:
window['jsFun']();
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函数和变量
ts调用参数是就是 window["参数名"],函数是window["函数名"]