Comments (4)
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.
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.
>({}).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.
Fixed now
from espruino.
Related Issues (20)
- An issue with void, delete and typeof and the detection of Errors
- Uncaught SyntaxError: Got [ERASED] expected EOF when writing to storage HOT 11
- Numeric separators result in error
- The following jit code doesn't seem to ever return HOT 1
- Compiler: The following function fails to compile HOT 2
- Graphics: drawing image in string in clipped rect fails when rotated HOT 1
- E.showMenu(): onchange method not called HOT 2
- Uint8Array constructor byteOffset is restricted to 2bytes HOT 2
- Does the build_board_docs.py script currently work HOT 5
- ArrayBuffers use firstChild - could they use lastChild?
- Math.sqrt e.compiledC() HOT 5
- Bangle.getPressure() fails intermittently HOT 17
- Stopping code execution when the terminal is not connected HOT 3
- Promises: resolve a new Promise HOT 16
- Constructor comparisons don't work HOT 2
- Workflow File for Linux HOT 12
- using newer compiler for ARM (13.2.Rel1) HOT 20
- SEGV on unknown address in jsvStringIteratorPrintfCallback HOT 3
- stack-overflow in jspeFactorFunctionCall
- Pretokenise JS functions included with `generate_js`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from espruino.