I've been working on an angular project and I've created a factory that provides global database methods. I decided to test it out in a jsfiddle to see if it's the right approach.
If you're interested, here's the link to the jsFiddle.
function DB () {
return {
newRecord: function () {
//create new record
var id = 3;
//this is the part I am wondering about
//is it ok to use this in this way??
this.setCurrentRecordId(id);
},
setCurrentRecordId: function (id) {
alert('setting id');
return localStorage.setItem('id', id);
},
getCurrentRecordId: function () {
return localStorage.getItem('id');
}
}
}
var dbStuff = new DB();
dbStuff.newRecord();
alert(dbStuff.getCurrentRecordId());
While everything seems to be functioning correctly, I'm curious to know if there might be a more efficient way to achieve the same result.
Thank you!