Code Monkey home page Code Monkey logo

Comments (4)

gfwilliams avatar gfwilliams commented on May 23, 2024

Added now. It does return false-positives for keys in prototypes though. We'll have to wait for #278 before we can get better.

from espruino.

rwaldron avatar rwaldron commented on May 23, 2024

It does return false-positives for keys in prototypes though.

Can you clarify?

This works correctly (except for the ones that cause errors):

var o = {
  key: 1
};

// Causes an error:
// console.log(
//   "should both be true: ",
//   o.hasOwnProperty("key"), Object.prototype.hasOwnProperty.call(o, "key")
// );

console.log("should be true: ", o.hasOwnProperty("key"));

function P() {
  this.own = 1;
}
P.prototype.key = 1;

// Causes an error:
// console.log("should be true: ", P.prototype.hasOwnProperty("key"));

var p = new P();

console.log("should be false: ", p.hasOwnProperty("key"));
console.log("should be true: ", p.hasOwnProperty("own"));

results in node/v8:

should be true:  true
should be false:  false
should be true:  true

results in espruino:

should be true:  true
should be false:  false
should be true:  true

from espruino.

gfwilliams avatar gfwilliams commented on May 23, 2024
>({}).hasOwnProperty("clone")
=true // should be false

So it's effectively function espruinoHasOwnProperty(s) { return o.hasOwnProperty(s) || o.prototype.hasOwnProperty(s); }

It's a pain, but IMO it's better than nothing (and is documented in the function's reference).

from espruino.

gfwilliams avatar gfwilliams commented on May 23, 2024

Fixed now

from espruino.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.