Coder Social home page Coder Social logo

Comments (4)

bnjbvr avatar bnjbvr commented on June 10, 2024 3

It might also be a source of confusion, because undefined then would be the symptom of two different causes: either a variable was indeed never defined, or it was a null reference that flew out of wasm. This would probably make debugging harder.

from reference-types.

sjrd avatar sjrd commented on June 10, 2024 2

I disagree. My experience as author/designer of Scala.js is that Scala's null maps perfectly well to JavaScript's null. And that, despite the fact that uninitialized fields of reference types are initialized with null (as per the JVM behavior).

The perfect mapping we found for undefined is actually unit (written () in Scala). This may seem weird, but is easily explained when you consider "void" functions: in JavaScript, a function without explicit return (or with return; without expression) returns undefined; in Scala, a function that does not return any value returns () of type Unit.

For nullable types, null will be the unique platform supported value to indicate that the expected value is absent.

The key words here are for nullable types. But wasm also has non-nullable types, for example ints, and those are initialized with 0/false/etc.. Obviously wasm's 0 cannot map to undefined in JS. Now, an "undefined int variable" in JS would also be initialized to undefined (because, hey, no types). So the mapping of uninitialized would be inconsistent between nullable types (map to undefined) and non-nullable types (map to 0, false, etc.). For that reason, I do not think the "this corresponds closely to the JS undefined" is actually accurate. Or at least, if it did correspond so closely, then so should 0, and we know that's nonsense.

from reference-types.

lars-t-hansen avatar lars-t-hansen commented on June 10, 2024

@rossberg, can you tag this as [js-api] so that it's plain that it doesn't block the core proposal? Thanks.

from reference-types.

rossberg avatar rossberg commented on June 10, 2024

Done. I also take the liberty to close this, since it is incompatible with the existing table API.

from reference-types.

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.