【问题标题】:How I can include prototype scripts on ionic2?如何在 ionic2 上包含原型脚本?
【发布时间】:2017-07-29 02:33:52
【问题描述】:

我想使用带有一些函数原型的文件,例如 Array.prototype.x( ... ),但我不知道如何将其包含为全局文件。

例子:

Array.ts

Array.prototype.x = function(i) {return this[i]}
Array.prototype.y = () => {return true}
Array.prototype.z = () => {return true}

pages/home/home.ts

import { Component } from '@angular/core';
@Component({
    selector: 'page-home',
    templateUrl: 'home.html'
})
export class HomePage {
    constructor() {}

    ionViewDidLoad() {
        let a [1,2,3,4,5,6,7,8,9,0];
        console.log(a.x()); // see Array.prototype.x()
        console.log(a.y()); // see Array.prototype.y()
        console.log(a.z()); // see Array.prototype.z()
    }
}

P.S:我的原型文件功能太多

【问题讨论】:

  • 只需将其包含在 head 中即可。
  • 好吧,我的“Array.ts”功能太多了……

标签: javascript angular typescript ionic2 prototype


【解决方案1】:

只需导入文件:

import { Component } from '@angular/core';
import './Array';
@Component({
    selector: 'page-home',
    templateUrl: 'home.html'
})
export class HomePage {
    constructor() {}

    ionViewDidLoad() {
        let a [1,2,3,4,5,6,7,8,9,0];
        console.log(a.x()); // see Array.prototype.x()
        console.log(a.y()); // see Array.prototype.y()
        console.log(a.z()); // see Array.prototype.z()
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-04
    • 2022-10-01
    • 2011-09-21
    • 2011-09-04
    相关资源
    最近更新 更多