Code Monkey home page Code Monkey logo

Comments (2)

snej avatar snej commented on September 27, 2024

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.

robertkrimen avatar robertkrimen commented on September 27, 2024

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)

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.