Comments (2)
Oh, the output of the test looks like:
value = otto.Value{_valueType:1, value:interface {}(nil)}
value = otto.Value{_valueType:2, value:interface {}(nil)}
Expected nil, got otto.Value{_valueType:2, value:interface {}(nil)}
from otto.
undefined is kind of a weird case, because it's not technically null.
In addition, I see the Export function as a sort of "best-effort" export. That is, try and export this ECMA value to something closer to Go, but if not, just return the otto.Value, since that is still a valid Go type/value.
So, theoretically, the best representation of an undefined value (which is entirely an ECMA concept) in Go is as an otto.Value.
That being said, I'm gonna take a page from JSON.stringify and consider Export to be like a JSON export. You can see this reasoning in more detail in section 15.12.3 of the ECMA-262 specification.
An undefined value in an array is represented by null (nil).
An undefined value in an object causes that property to not exist in the exported result.
Caveat: The two rules above are good, and should not change, but exporting an undefined value by itself is undefined, and could change in the future. For now, it will export nil.
from otto.
Related Issues (20)
- Compile throws error HOT 3
- JS VM crashing go HOT 2
- Errors caused by different go versions HOT 3
- TestBinaryShiftOperation test fails HOT 31
- Parser don't allow leading 0 HOT 8
- `panic: strconv.ParseInt: parsing "toJSON": invalid syntax` on `ToValue` a `map` HOT 3
- new Date can't not parse datetime string HOT 2
- Memory is slowly increasing until OOM HOT 4
- "use strict" is not in effect HOT 7
- Overview of extending thrid party packages
- Implementation of the export and import keywords to support, amongst others, unit tests. HOT 3
- dates and timezone HOT 1
- How do I call a function that I extract from other javascript code
- Doe this framework support wsam? HOT 1
- fatal error: concurrent map write HOT 5
- How to obtain the values of jump related variables such as window.location.href?
- 多线程的时候会报错 HOT 2
- Code generator: AST ⇒ javascript code HOT 3
- Value of json expression is `undefined` HOT 1
- `let x=1` and `const x=1` don't work. HOT 3
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 otto.