2016-05-04 7 views
0

私は、次のJSを見ています。これは、私が.d.tsファイルを作成しているプロジェクトの多くの1つです。Typescriptの定義。名前付き関数式(NFE)

BatchBuffer.js

var Buffer = function(size) 
{ 

    this.vertices = new ArrayBuffer(size); 

    /** 
     * View on the vertices as a Float32Array for positions 
     * 
     * @member {Float32Array} 
     */ 
    this.float32View = new Float32Array(this.vertices); 

    /** 
     * View on the vertices as a Uint32Array for uvs 
     * 
     * @member {Float32Array} 
     */ 
    this.uint32View = new Uint32Array(this.vertices); 
}; 

module.exports = Buffer; 

Buffer.prototype.destroy = function(){ 
    this.vertices = null; 
    this.positions = null; 
    this.uvs = null; 
    this.colors = null; 
}; 

グーグルto here上の検索では、これがNamed Function Expression (NFE)ですが、私は迷子に始めたことを私に伝えます。このモジュールはさらに混乱を招いています。

これを正しく定義するにはどうすればよいですか?名前はバグベア(BatchBufferまたはBuffer)ですが、これは正確に見えますか?

export module BatchBuffer { 

    export var vertices: ArrayBuffer; 
    export var float32View: number[]; 
    export var uint32View: number[]; 

    export function destroy(): void; 

} 

私はこのような類似したNFEファイルを叩いていますので、私の定義が正確であると私は助言や確認が必要だと感じています。

ありがとうございました。

が編集されました。

Ryan's Answerを参照してください。

プロジェクト内の他のほとんどのクラスは(似た!)見例えば、この擬似へ:

MyClass.js

function MyClass(something) 
{ 
    /** 
    * Some property 
    * 
    * @member {number} 
    */ 
    this.something = something; 
} 

MyClass.prototype.constructor = MyClass; 
module.exports = MyClass; 

MyClass.prototype.hi = function() 
{ 
} 

私は同じように見えるものに意味を割り当てるました。細部は私を逃れるが。それを知ることは、クラスは私にうまく合う。

答えて

1

ここにはクラスがあります - new(それはprototypeのプロパティに関数を割り当てているのでわかります)のプロパティとメソッドを持っています。

declare class Buffer { 
    constructor(size: number); 

    vertices: ArrayBuffer; 
    float32View: Float32Array; 
    uint32View: Float32Array; 

    uvs: any; // not sure of type 
    colors: any; // not sure of type 
    positions: any; // not sure of type 

    destroy(): void; 
} 

// expresses "module.exports = Buffer" 
export = Buffer; 
+0

いやはや:

あなたのファイルには、次のようになります!もう一度Ryanに感謝します。 – Clark

関連する問題