2016-04-17 4 views
1

クラスのオブジェクトを配列に格納し、オブジェクトget関数を使用する方法は?あなたが.typeが必要.getType()JavaScript ecma6のオブジェクトリファレンス

//in storage class 
export class DataStorage{ 
    constructor(type, value){ 
     this._type = type; 
     this._value = value; 
    } 
    get type() { 
     return this._type; 
    } 

//store objects of type storage class 
import {DataStorage} from "./DataStorage.js"; 
export var aDS = []; 
export function addDataStorage(type, value){ 
    aDS.push(new DataStorage(type, value)); 
} 

//use get function in storage class 
import * as DS from "./AllDataStorage.js"; 
export function calculate(){ 
    for(var i = 0; i < DS.aDS.length; i++){ 
     console.log(DS.aDS[i].getType()); //Does not work 
    } 
} 
+0

これはES6とは関係ありません。 – Bergi

答えて

1

あなたはゲッター機能を持っている、あなたは必要ありません。

+0

ありがとう!それを解決する! – Esset

関連する問題