Collection type javascript library (equivalent to using Blocks) ...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lobo

    Collection type javascript library (equivalent to using Blocks) ...

    I'm wondering how expensive and (in)efficient is to use Collection
    type javascript library functions (similar to using Blocks), instead
    of repeating the 'for' iterator over and over across a large
    application.

    I'm afraid that instantiating javascript Functions to act as Blocks in
    these cases might require many more internal javascript resources
    (time / memory) compared to using the 'for' statement - ?.

    I would not want this to be the cause for my apps to eventually run
    much slower (and consuming more memory).

    For reference, define the following Collection type javascript
    function:

    function array_do (theArray, theBlock) {
    for (var i=0; i<theArray.leng th; i++) {
    var eachElement = theArray[i];
    theBlock(eachEl ement);
    }
    }

    .... and use it as follows:

    array_do (testArray, function(each) { ... do something with
    'each' ... } );

    As you can see I would have to create a new javascript function each
    time I need to execute the array_do function.

    Thanks in advance.
  • VK

    #2
    Re: Collection type javascript library (equivalent to using Blocks)...

    On Feb 7, 6:54 pm, Lobo <carlosgali...@ gmail.comwrote:
    I'm wondering how expensive and (in)efficient is to use Collection
    type javascript library functions (similar to using Blocks), instead
    of repeating the 'for' iterator over and over across a large
    application.
    Collections and blocks (as defined in your post) are from ol' good
    linear programming. In OOP you are having a set of objects with
    particular methods and properties and you are calling the necessary
    method. If you don't need to keep particular data in each method for
    each object instance then we define the method as static so no matter
    how many object instance are created, they all will be using the same
    scavenger (heap?)
    In your case (if it is your case) that might be:

    function MyObject {
    // per-instance
    // methods and properties
    }

    MyObject.protot ype.staticMetho d = function() {
    // this.doSomethin g
    }

    and then could be

    for (var i=0; i<myObjectsArra y.length; i++) {
    myObjectsArray[i].staticMethod() ;
    }

    this way if cannot tell before runtime what kind of staticMethod you
    may need and either it can be static or not: that would mean that your
    OOP schema has a failure in it or not ready yet so it needs more
    thinking over before implementing.

    There is nothing criminal in using the old linear programming
    approach, I just wanted to stress out that what you are doing is not
    OOP.

    <snip>
    As you can see I would have to create a new javascript function each
    time I need to execute the array_do function.
    Not in OOP

    Comment

    Working...