Skip to content

Instantly share code, notes, and snippets.

@enricopolanski
Last active February 23, 2018 15:46
Show Gist options
  • Save enricopolanski/d51192fbd00a34a96e2f757988299600 to your computer and use it in GitHub Desktop.
Save enricopolanski/d51192fbd00a34a96e2f757988299600 to your computer and use it in GitHub Desktop.
userPlan = {
// plenty of stuff
startingWeek = Date object; // such as Mon Feb 19 2018 16:34:08 GMT+0100 (W. Europe Stand…
// other stuff
}
function saveData(data){
console.log(this) // => correctly logs the userPlan object, including startingWeek property
console.log(this.data) // logs 'undefined'
localStorage.setItem(data, JSON.stringify(this.data)); // => saves: 'startingWeek' : undefined;
}
saveData.call(userPlan, 'startingWeek');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment