Comments (2)
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.
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)
- Output something more helpful in case of unmatched brackets
- Disable implicit global names
- Standard library functions should have parameters if they are stringified
- Add zlib and MD5/SHA-1/SHA-2 from OpenSSL
- C stack overflows
- `catch` operator? HOT 2
- Add INI library
- Add CSV library HOT 1
- Autoconf error! HOT 1
- `errno` and `rocket::format()`
- Remove `Value::type_mask()` HOT 1
- Generalize for-each loops
- Optimize flat function calls
- Constant Propagation
- Optimization records HOT 3
- mutex in 'rocket/xmemory' is slow HOT 1
- Grant ?? highest precedence
- status of `continue` with in a for-each loop is not forwarded correctly
- `Abstract_Hooks` needs some cleanup
- `each` clause in `switch` statements HOT 2
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 asteria.