Skip to content

TypeError: obj.hasOwnProperty is not a function at filterKeys #7

@qwabra

Description

@qwabra

err in nodejs http.reques

const http = require("http");
const treeify = require('treeify');
let r = http.request({
    hostname: 'ya.ru'
}, (_r) => {
    let str = treeify.asTree(_r);
    console.log(str);
});
r.on('error', console.error);
r.write('');
r.end();

https://github.com/notatestuser/treeify/blob/master/treeify.js#L32

  let count = ((count = 0, timer = null) => () => {
    count++;
    clearTimeout(timer)
    timer = setTimeout(() => {
      console.log(`"if (!obj.hasOwnProperty)" counted:${count}`)
    }, 1e3);
  })()
  function filterKeys(obj, hideFunctions) {
    var keys = [];
    for (var branch in obj) {
      // always exclude anything in the object's prototype
      if (!obj.hasOwnProperty) count()
      if (!obj.hasOwnProperty || !obj.hasOwnProperty(branch)) {
        continue;
      }
      // ... and hide any keys mapped to functions if we've been told to
      if (hideFunctions && ((typeof obj[branch]) === "function")) {
        continue;
      }
      keys.push(branch);
    }
    return keys;
  }

result:
"if (!obj.hasOwnProperty)" counted:71

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions