typescript 调用JavaScript

  1. 把js文件放到src/assets目录下。例如我的js文件为 remogeo.js

  2. 在src目录下的index.html中增加如下语句:

  1. 下面是我的 interactive.js中代码:

    function JSGoBack(tit, status) { // 返回按钮类

     this._tit = tit;
    
     this._status = status;
    

    }

    JSGoBack.prototype = {

     _getValue: function () {
    
         console.log('this._tit:' + this._tit + ',this._status:' + this._status);
    
     },
    

    _ interactiveFun: function () {

         //  javascript: android.setmTitle(this._tit, this._status);
    
     }
    

    }

  2. 全局断言:declare var JSGoBack: any; 其中的JSGoBack是根据 interactive.js中的函数名定义的。

  3. 创建对象并使用

    const jsGoBack = new JSGoBack(‘任务’, ‘yes’);

    jsGoBack._getValue();

  4. 结果

    this._tit:任务,this._status:yes

内容为原创,如有转载请注明来源: http://www.dreamload.cn/blog/?p=839

猜你喜欢

转载自blog.csdn.net/Kindergarten_Sir/article/details/108589278