Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Agreed. Maybe an example of how JavaScript/CoffeeScript would behave if it had dynamic scope semantics could help:

  // In dynamically scoped JS...
  var f = function() { alert a; }
  f(); // would throw an error as expected, but...
  var g = function() {
    var a = 5;
    f(); // would now work because `a` now exists.
  } // The scope of `a` ends here though, so...
  f(); // would throw again, but if we give life to the dinamically scoped `a` again...
  var a = 6;
  f(); // now works! Printing 6 as "expected" (at least after swallowing dynamic scope).


From the vicious flame-fest that precipitated this post:

    x = 'lexical'

    acid = ->
      alert "#{x}ly scoped"

    test = (x) ->
      acid()
  
    test('dynamic')




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: