Live data from Hacker News

JavaScript: what is "this"?

howtonode.org

1–10 of 49 posts

Re: JavaScript: what is "this"?

#3
It's not entirely our fault, the language was designed to work like one thing (scheme-like), but look like another (c-like).

The baseless assertion rears its head again. People keep repeating this, and it's not true. JavaScript is not Scheme. It's not any more Scheme-like than Java, C++, Python, Perl, or many other languages. Lua and Ruby are far more Scheme-like than JavaScript.

I've commented before on people repeating this statement without ever examining it. I don't want to dredge up the arguments against it again ( http://news.ycombinator.com/item?id=1171202 ), mostly I just want to whine at it because it's so annoying. Why do you have to make JavaScript seem like something it's not? Are you trying to seem cooler by equating the language you work in to Scheme? What's wrong with JavaScript just being what it is?

Re: JavaScript: what is "this"?

#4
post #3

It's not entirely our fault, the language was designed to work like one thing (scheme-like), but look like another (c-like). The baseless assertion rears its head again. People keep repeating this, and it's not true. JavaScript is not Scheme. It's not any more Scheme-like than Java, C++, Python, Perl, or many other languages. Lua and Ruby are far more Scheme-like than JavaScript. I've commented before on people repea…

I think the author is just citing how influential Scheme was to JavaScript's design.

In "Coders at Work", page 141, Brendan Eich talks about wanting to build a scheme-like language for the browser. The c-like syntax was adopted because Netscape wanted it to look like Java.

Re: JavaScript: what is "this"?

#5
post #3

It's not entirely our fault, the language was designed to work like one thing (scheme-like), but look like another (c-like). The baseless assertion rears its head again. People keep repeating this, and it's not true. JavaScript is not Scheme. It's not any more Scheme-like than Java, C++, Python, Perl, or many other languages. Lua and Ruby are far more Scheme-like than JavaScript. I've commented before on people repea…

JavaScript definitely isn't Scheme (just as it definitely isn't Java either), but it is correct that it was conceived as a somewhat Scheme-like language with an OO-model inspired by Self, but for marketing reasons it was given a superficially Java-like syntax (and name!).

It is interesting to imagine what could have happened if Netscape had shipped with a Lisp. Probably a lot more people would hate Lisp today!

Re: JavaScript: what is "this"?

#6
post #3

It's not entirely our fault, the language was designed to work like one thing (scheme-like), but look like another (c-like). The baseless assertion rears its head again. People keep repeating this, and it's not true. JavaScript is not Scheme. It's not any more Scheme-like than Java, C++, Python, Perl, or many other languages. Lua and Ruby are far more Scheme-like than JavaScript. I've commented before on people repea…

I think the author is just citing how influential Scheme was to JavaScript's design. In "Coders at Work", page 141, Brendan Eich talks about wanting to build a scheme-like language for the browser. The c-like syntax was adopted because Netscape wanted it to look like Java.

Maybe he wanted to. If that was his goal, I think he failed.

    Scheme: First-class functions, tail-call elimination, macros,
            hygienic macros, write and parse the AST directly.
    JavaScript: First-class functions.
    
    Scheme: Immutable arrays and lists, mutable strings.
    JavaScript: Mutable-only arrays, immutable-only strings.
Yes, I have, and have read, Coders at Work. I don't see how it's relevant. JavaScript and Scheme share only one defining feature in common, first-class functions. It's an important feature, no doubt, but many other languages have it: C/Objective-C (with Apple's blocks extension), C++ (with Boost.Lambda), Perl, Python, Ruby, Lua, Io, OCaml, ML, Haskell, the list goes on. People compared Perl to Lisp once, briefly, when it was one of the few dynamic languages, but they don't anymore.

Re: JavaScript: what is "this"?

#8
post #3

It's not entirely our fault, the language was designed to work like one thing (scheme-like), but look like another (c-like). The baseless assertion rears its head again. People keep repeating this, and it's not true. JavaScript is not Scheme. It's not any more Scheme-like than Java, C++, Python, Perl, or many other languages. Lua and Ruby are far more Scheme-like than JavaScript. I've commented before on people repea…

This point of view is also maintained by D Crockford[1] who is supposed to know JavaScript's background.

[1] IIRC eg in this presentation: http://www.infoq.com/presentations/The-State-and-Future-of-J...

Re: JavaScript: what is "this"?

#9
Honestly, I think this is all too complicated. In Javascript, when you look at a line like this:

  a=1
you have to guess in which scope it changes or creates the variable a. I prefer the way PHP is dealing with scope. You simply know that "a=1" is only affecting the current scope.

Re: JavaScript: what is "this"?

#10
post #9

Honestly, I think this is all too complicated. In Javascript, when you look at a line like this: a=1 you have to guess in which scope it changes or creates the variable a. I prefer the way PHP is dealing with scope. You simply know that "a=1" is only affecting the current scope.

Which is why PHP is so much less flexible than JS. Also try this:

  $a = 1;
  function qqq() {
    global $a;
    unset( $a );
  }
  qqq();
  var_dump( $a );
P.S.: In PHP 5.1.6 calling unset() actually increases memory usage...
Post reply on HN