Coder Social home page Coder Social logo

Comments (2)

lhmouse avatar lhmouse commented on May 30, 2024

I think that JavaScript is right. Inside the initializer of a variable, it should be considered to have been declared and visible. It is just the ReferenceError: a is not defined message that is vague and cryptic. This principle also holds in C and C++ although copying an uninitialized variable results in undefined behavior.

ATM in Asteria, in such a case the variable is considered as if it was declared as const VAR = null but I personally prefer the Node.js solution; it should be invalid to read from or write to such variables until its initialization is complete.

Note that this does not forbid referencing the variable (not reading or writing):

var a = func() { return typeof a;  };   // `a` is a function returning the type of `a`,
                                        // which is not invalid.
var b = a;   // `b` is the same function.
std.debug.print("typeof `a` is `$1`.", b());  // `function`

a = 42;
std.debug.print("typeof `a` is `$1`.", b());  // `integer`

from asteria.

lhmouse avatar lhmouse commented on May 30, 2024

Fixed so far. Now we get this in the REPL:

#2:1> var a = func(){ return a;  };  std.debug.print("a = $1", a);
2020-01-05 22:21:38.856 @@ asteria/src/library/bindings_debug.cpp:27
        a = <function> [[`<closure>._1() @ snippet #2:1`]]
* result #2: <void>

from asteria.

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.