www.webdeveloper.com
Results 1 to 2 of 2

Thread: Help with JavaScript Objects

  1. #1
    Join Date
    Sep 2012
    Posts
    1

    Question Help with JavaScript Objects

    Hello,

    I'm working on a webpage and looking at using Objects to store data in a frame, allowing users to reload the target area for navigation. If the user moves to another page, the object have the new data added while keeping the original data. The idea came from the "Planet" Object example in the "JavaScript Bible (7th Edition)" (A search for "javascript bible" returns a Google Books reference to 4th edition book on Wiley's site).

    The best way to describe the Object I'm looking at would be an Excel spreadsheet. I have a "Worksheet" with multiple "Sheets" and, within that, "Cells". The "Cells" are broken out further into their respective properties and arranged in Columns and Rows. This is just an example, but is pretty close to the actual project. My plan is to populate the "Cells" with the values from a database onto a webpage. If the user switches to another "Sheet", new data is added to the Object and the old data is maintained. If the user switches back to the first "Sheet", the data will be accessed from the Object instead of reloading the page.

    The webpage will have users increase the size, possibly exponentially, of the object over time. In the begining, data will be limited to a few cells.

    I'm mostly looking for references to learn the process, diving into the details is how I learn. If you can provide one, that is great! If you have a code example, that would work as well.

    So, here are my questions:

    • Is this the most efficient way of doing things? I am working with an Apache/MySQL/PHP setup. Should I be looking into other options? If there is a better way, it may need to wait for version 2.0, but I'm willing to look into it.
    • How do you "navigate" through an Object? For example, I want to switch to "Sheet2" and populate the "Cell" with an address of Column 24, Row 13. In the "Planet" Object tutorial ("JavaScript Bible"), they use an Array of Objects. Should the "Workbook" and "Sheets" all be Arrays with "Cell" Objects?
    • Is there a good resource, on the web or a book, that explains Objects and Prototypes in more detail than "JavaScript Bible (7th Edition)"?
    • Do you see a problem with the Object getting too big? There are 184,110 "Cells" in each "Workbook". Additionally, each "Cell" can have a minimum of 20-30 properties. So it is possible to have 5,523,300 "entries". I don't see it getting that huge as some cells will not have data (using smart coding, not populating data for entries with no records, etc), but 2 million "entries" would be possible over time.


    Any help would be greatly appreciated!

    Thanks

    Todd

  2. #2
    Join Date
    Feb 2003
    Location
    Michigan, USA
    Posts
    5,774
    Object size
    The only problem I see here relates to performance: RAM and the processing time it takes to traverse the object tree. From what I gather, a mobile version is probably out of the question.

    JavaScript Object Reference
    This is a good one from the folks at Mozilla: https://developer.mozilla.org/en-US/...e_Object_Model

    So is this: https://developer.mozilla.org/en-US/...ted_JavaScript

    Also, for some function wrappers for easing the creation of JavaScript "classes", check out the links below. I created my own wrappers:

    Code:
    BaseClass = Object.extend({
      includes: SomeMixin,
      self: {
        // class level methods: BaseClass.foo()
      },
      prototype: {
        // instance level methods: x = new BaseClass(); x.foo()
      }
    });
    
    var Mixin = {
      self: {
        // class level methods
      },
      prototype: {
        // instance level methods
      }
    };
    
    SomeClass.include(Mixin);
    Source code: https://github.com/gburghardt/JsLib/...es/Function.js

    And how to use it: https://github.com/gburghardt/JsLib/...nction.spec.js

    You'll want to create an object hierarchy:

    Spreadsheet
    * Has many Workbooks

    WorkBook
    * Has many columns

    Column
    * Has Many cells

    Cell
    * Has the contents you are looking for.

    Some pseudo code to start you off with architecting your spreadsheet:

    Code:
    var spreadsheet = new Spreadsheet();
    var workbook = spreadsheet.createWorkBook("workbook1");
    var column = workbook.createColumn(0);
    column.createCell("Contents go here", 0);
    column.createCell("Something else", 1);

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles