Bootstrap

typescript 调用JavaScript

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

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

   <script type="text/javascript" src="assets/interactive.js"></script>
  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);

    }

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

  2. 创建对象并使用

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

jsGoBack._getValue();
  1. 结果
   this._tit:任务,this._status:yes

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

;