You need to push a newly created item to your array like below:
CoinArray.push(new Coin.Create('123));
On the other hand if you want to create an object with keys ids and values corresponding Coin objects, you should try this:
CoinDictionary = {};
CoinDictionary['123'] = new Coin.Create('123');
Note:
I think that you should refactor a bit the Coin if you want to use it as a constructor function:
function Coin(id){
this.id = id;
}
Doing this change you can use it as below:
CoinArray.push(new Coin('123'));
function Coin(id){
this.id = id;
}
var CoinArray = [];
CoinArray.push(new Coin('123'));
CoinArray.push(new Coin('456'));
CoinArray.push(new Coin('789'));
console.log(CoinArray);
Update
At the end I want to have array with object and for example I will
take first el of array, and execute other method from Coin class.
For this purpose If I were you I would have gone with the creation of an object with keys the ids and values references to Coin objects:
function Coin(id){
this.id = id;
}
Coin.prototype.start = function(){
console.log("game with id "+this.id+" started.");
}
Coins = {}
Coins['123'] = new Coin('123');
Coins['456'] = new Coin('456');
Coins['789'] = new Coin('789');
Coins['456'].start();
CoinArrayto look like after creating the array like that? That'll help us figure out how to help.id -> coinmap?