Uploaded image for project: 'CouchDB'
  1. CouchDB
  2. COUCHDB-1300

Array.prototype isn't working properly

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Not A Problem
    • 1.1
    • None
    • JavaScript View Server
    • Ubuntu 11.04, node.couchapp, commonJS

    • Regular Contributors Level (Easy to Medium)

    Description

      ##file helpers.js in views/lib/common
      const _ = require("views/lib/underscore");
      Array.prototype.compact = function()

      {return _.compact(this);}

      ;
      Array.prototype.flatten = function()

      {return _.flatten(this);}

      ;

      //this function is called from views.someName.map
      function commonProperties(doc){
      arr = [];
      arr = arr.compact();
      log(arr);
      log("is array?");
      log(toString.call(doc.store.taxes));
      log(doc.store.taxes);
      //log(doc.store.taxes.compact());
      log("is safe array?");
      log(toString.call(safe.array(doc.store.taxes)));
      log(safe.array(doc.store.taxes));
      //log(safe.array(doc.store.taxes).compact());
      log("array?");
      log(toString.call(Array(safe.array(doc.store.taxes))));
      log(Array(doc.store.taxes));
      log(Array(doc.store.taxes).compact());
      ...

      ::LOG

      [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: []
      [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: is array?
      [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: [object Array]
      [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: [

      {"taxId":0,"number":"000000","percent":8}

      ,

      {"taxId":1,"number":"","percent":5}

      ,

      {"taxId":2,"number":"","percent":1}

      ]
      [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: is safe array?
      [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: [object Array]
      [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: [

      {"taxId":0,"number":"000000","percent":8}

      ,

      {"taxId":1,"number":"","percent":5}

      ,

      {"taxId":2,"number":"","percent":1}

      ]
      [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: array?
      [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: [object Array]
      [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: [[

      {"taxId":0,"number":"000000","percent":8}

      ,

      {"taxId":1,"number":"","percent":5}

      ,

      {"taxId":2,"number":"","percent":1}

      ]]

      the .compact() lines that are commented out cause errors:
      [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: []
      [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: is array?
      [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: [object Array]
      [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: [

      {"taxId":0,"number":"000000","percent":8}

      ,

      {"taxId":1,"number":"","percent":5}

      ,

      {"taxId":2,"number":"","percent":1}

      ]
      [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: function raised exception (new TypeError("doc.store.taxes.compact is not a function", "", 29)) with doc._id RT7-RT7-31-20

      the first logs show that doc.store.taxes is an array, why do i need to use Array() on it in order to use the prototype functions?

      Attachments

        Activity

          People

            Unassigned Unassigned
            boxie paul iannazzo
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: