JSFiddle - React, Tailwind, and code Playground

by secretgspot

JavaScript

var SceneModule = function()    {
    var scene, createScene, updateScene, getScene;

    scene   =   {
        name : '',
        width : 100,
        height : 100
    };

    createScene = function(params)  {
        for(var key in params)  {
            scene[key] = params[key];
        }

        return this;
    };

    updateScene = function(params)  {
        scene[params.attr] = params.value;
    };

    getScene = function()   {
        return scene;
    }

    return {
        create : function(params)   {
            createScene(params);
            return this;
        },

        update : function(params)   {
            updateScene(params);
            return this;
        },

        get : function()    {
            return getScene();
        }
    };
};

var SceneArray = [], tempArray;

SceneArray.push(
    SceneModule().create({
        name : 'scene 1',
        width : 100,
        height : 100
    }),
    SceneModule().create({
        name : 'scene 2',
        width : 100,
        height : 100
    }),
    SceneModule().create({
        name : 'scene 3',
        width : 100,
        height : 100
    })
);

localStorage.setItem('scene', JSON.stringify(SceneArray));

var tempArray = JSON.parse(localStorage.getItem('scene'));

/**
 * Print string [object object, object object, object object];
 * not the SceneArray Structure; 
 */
console.log(tempArray); // [Object, Object, Object]