I am making a change inside the main function array of the object, but this is changing several values, including variable outside the object, which can not happen. How can I fix this?
var trackList [
{id: 1, name: "Isometric (intro)", artist: "Madeon", currentDuration: 0, fullDuration: "5", …},
{id: 2, name: "You're On", artist: "Madeon", currentDuration: 0, fullDuration: "15", …}
]
// Nesta parte alterto as informações com o this do trackObject.track
trackObject.prototype._nextTrack = function(newTrack){
clearTimeout(this.loadingTimer);
this._setTrackName.call(this, newTrack.name); // isto altera TODOS os valores do trackList[value].name dentro de var trackList
}
// Esta e uma orientação para alterar o array dentro do this.track.name em trackObject.
trackObject.prototype._setTrackName = function(name){
this.track.name = name;
}
trackObject.prototype._callNextTrack = function(){
trackCurrentListId = trackCurrentListId + 1;
if(trackCurrentListId >= trackList.length) trackCurrentListId = 0;
var track = trackList[trackCurrentListId];
this._nextTrack.call(this, track); // envio as novas informações de atualização do objeto
}
function trackObject(track){
this.track = track;
// track == {id: 1, name: "Isometric (intro)", artist: "Madeon", currentDuration: 0, fullDuration: "5", …}
this._nextButton();
this._updateTrack();
}
var track = {id: 1, name: "Isometric (intro)", artist: "Madeon", currentDuration: 0, fullDuration: "5", …}
new trackObject(track);