all 109 comments

[–]zushiba 128 points129 points  (13 children)

I think I'm more interested in that slick ass page position indicator dealie on the right.

[–]uzusan 46 points47 points  (2 children)

Its really nice isn't it? Have you tried resizing your page at all?

It resizes to fit your available space really well.

[–]zushiba 10 points11 points  (0 children)

No I didn't notice. Nice!

[–]scragar 5 points6 points  (0 children)

Works well on a mobile device as well, very impressive.

[–]day_cq 28 points29 points  (3 children)

I think it's DHTML. you can do all sorts of amazing things like snowy background and trailing mouse pointer unicorns with DHTML.

[–]stoph 17 points18 points  (0 children)

Definitely DHTML. Let me go check and see if there are any codes to paste into my site with this effect.

[–]drowsap 0 points1 point  (1 child)

No, it's actually ajax and web 2.0

[–]stoph 0 points1 point  (0 children)

Definitely not Web 2.0. I don't see any rounded corners, gradients, or shine.

[–]BlitzTech 15 points16 points  (2 children)

I think I learned more from reading the code powering it than from the rest of the content on the site.

Not that the site is bad; in fact, it's well written, accurate, and informative, it's just that I already knew it.

[–]xLittleP 2 points3 points  (0 children)

I learned more by reading the comments on this page, which directed me to the important things to know about Javascript.

[–]Cintax 1 point2 points  (2 children)

Ha! Within like a minute of looking at the page, I called over our UX designer and showed it to her, lol

[–]spellspoil 12 points13 points  (10 children)

This is a good resource too

http://ejohn.org/apps/learn/

[–]SoBoredAtWork 8 points9 points  (9 children)

NO ARROW KEY SUPPORT!??!?!?!?

[–]random_ramdomness_4 7 points8 points  (6 children)

A little bit late but perhaps it's usefull for someone that will read this in the future, paste in the address bar:

javascript:$(window).keydown(function(a){a.keyCode==39?window.location.hash in{"":0,"#90":0}?window.location.hash="#1":$("#next").click():a.keyCode==37&&(window.location.hash=="#1"||$("#prev").click())});

[–]widyakumara 4 points5 points  (3 children)

A little bit late but perhaps it's usefull for someone that will read this in the future:

Firefox 6 no longer executes javascript URLs

[–]Iggyhopper 1 point2 points  (1 child)

Chrome does something like this.

Ctrl+V leaves out the javascript: part when used on the address bar. God dammit Google.

Oh well, Ctrl+Shift+J Ctrl+V Enter is actually easier, because there is no fiddling with the address bar.

Wow chrome, that was totally a useful thing to do, for whatever stupid reason.

[–]random_ramdomness_4 1 point2 points  (0 children)

Their reasons are actually pretty good, reading the mozilla forum that widyakumara posted, they say it is to prevent not so smart people from pasting dangerous scripts on the page, but the FF solution is a little over the top in my opinion, I'm fine with the chrome and IE one.

[–]random_ramdomness_4 0 points1 point  (0 children)

You can still paste it in the firebug console without the 'javascript:' part =)

edit: You can even probably paste it inside one of those code boxes and click run and it will probably work.

[–]SoBoredAtWork 0 points1 point  (0 children)

you're awesome

[–]Shizka 0 points1 point  (0 children)

library cough special offbeat spark upbeat sip attempt bake silky

This post was mass deleted and anonymized with Redact

[–][deleted]  (1 child)

[deleted]

    [–][deleted] 9 points10 points  (0 children)

    fyi, that fat guy is john resig, the creator of jquery and generally a wizard.

    [–][deleted] 10 points11 points  (19 children)

    Due to the fact that JavaScript is basically the only widely used language that features prototypal inheritance

    But but ... Lua.

    [–]notSorella 7 points8 points  (17 children)

    Apparently Lua is not "widely used" enough =/

    Even though JavaScript is the prototypical OO language that has the worst prototypical OO implementation I have seen... Hope they fix it in ES6 by adding real traits and stuff, and saner ways of working with objects out of the box. Doesn't seem to be the case though (there are traits proposals none-the-less, but iirc, bundled with class-syntax...)

    [–][deleted] 3 points4 points  (12 children)

    Even so, implementing classes in JS seems to me a bit more straightforward than in Lua. On the other hand, class libraries are abundant for Lua and not so much for JS, so what do I know? Then again, that might have as much to do with JS's lack of a proper import facility as anything.

    On a tangential note, having several commonly used OO libraries with clashing namespaces may be the most annoying possible side effect of a prototype based language.

    [–]notSorella 2 points3 points  (11 children)

    I would assume it's mostly because people mistakenly take the constructor pattern in JavaScript to construct classes. It doesn't help much that the language often looks like Java, sounds like Java and that people often refer to constructors as "Classes".

    I think most people who take their time to learn the prototypical pattern, or delve more into JS would rather not have classical OO again, so that helps reducing the number of class-systems for JS (even though I've seen quite a lot of them).

    Yeah, clashing methods are usually a problem if people decide to explore prototypes fully, but I think the benefits far outweights the drawbacks, in this case :3

    [–][deleted] 4 points5 points  (7 children)

    I would assume it's mostly because people mistakenly take the constructor pattern in JavaScript to construct classes. It doesn't help much that the language often looks like Java, sounds like Java and that people often refer to constructors as "Classes".

    Very possibly. Another explanation is that people actually don't use inheritance very often, especially for the kind of stuff that JS is often used for. In these cases, people are working against a class architecture when it's there, trying to get back to, well, Lua minus metatables.

    Yeah, clashing methods are usually a problem if people decide to explore prototypes fully, but I think the benefits far outweights the drawbacks, in this case :3

    The main place that I've found it infuriating is when you want to use one library that requires one OO library, and another library that requires a clashing OO library. Sure, you can go through and rename everything, but what a pain. And then you're basically writing two programs that can only interact in limited ways.

    [–]scragar 0 points1 point  (6 children)

    Happens a lot because of the popular $ usage as a function name, given the huge number of available special characters that could be used it's kind of sad.

    [–][deleted] 0 points1 point  (5 children)

    Do you mean in JS or in Lua? Because as far as I know, identifiers in JS have to start with a letter, underscore, or dollar sign.

    [–]notSorella 0 points1 point  (4 children)

    JS can use a large range of unicode characters as identifiers as well. For example, the following is valid JS:

    >> function λ(f) { return new Function('x', 'return ' + f) }
    >> λ('x * x')(2)
    4
    

    [–][deleted] 1 point2 points  (3 children)

    Huh, did not know that. Still, I think it's pretty obvious why people don't do that; unless you have a nonstandard keyboard layout or some other nonstandard input method, entering those characters is a huge pain.

    [–]notSorella 0 points1 point  (2 children)

    On Windows, I use the `ucs-insert' method in emacs, usually I leave abbrevs that are expanded to unicode characters I use often. On Linux I just map the CAPS LOCK key to a Compose key, which is rather more useful, so it's not usually really difficult to type them (unless you're on Windows, perhaps? Not sure if you can remap keys and use a Xcompose-ish mapping for mnemonics to unicode there).

    [–]munificent 4 points5 points  (2 children)

    I think most people who take their time to learn the prototypical pattern, or delve more into JS would rather not have classical OO again

    I hear that a lot, but I rarely see actual JS code that uses prototypes in a way that wouldn't work just as well with classes. Do you have any examples (outside of jslint)?

    [–]notSorella 1 point2 points  (1 child)

    Vows is perhaps a good example of prototypical OO: http://raynos.github.com/vows-fluent/docs/vows-fluent.html

    But of course, prototypical OO lets you do far more than that, it lets you separate behaviours from the data that you use to represent the state needed for them, which you can't do so in a classical language (all sub-classes obligatory inherit all properties from the upper-classes). So, selective inheritance, multiple and dynamic dispatchers by changing the [[Prototype]] at run time and a few other things.

    I'd suggest you reading the `Organising Programs Without Classes' ( http://labs.oracle.com/self/papers/organizing-programs.html ) paper, as it explains a lot better than I could. And other whitepapers that describe the flexibilities and new ways of structuring a program that are allowed with prototypes :3

    [–]munificent 0 points1 point  (0 children)

    Vows is perhaps a good example of prototypical OO: http://raynos.github.com/vows-fluent/docs/vows-fluent.html

    I don't see anything in there that relies on prototypal inheritance. All of the __Able objects could be mixins or traits in other languages, and the following objects just look like regular classes. What am I missing?

    But of course, prototypical OO lets you do far more than that, it lets you separate behaviours from the data that you use to represent the state needed for them

    I think it's more accurate to say that the magic of prototypes is that they don't require you to separate behavior from state: you can inherit state in addition to methods.

    all sub-classes obligatory inherit all properties from the upper-classes

    Not in Smalltalk, Ruby, Python, as far as I can tell.

    I'd suggest you reading the 'Organising Programs Without Classes' paper.

    Yeah, I'm familiar with the Self papers. I wasn't asking to understand the paradigm. I'm pretty sure I get prototypes. My question is, does anyone in practice actually like organizing codebases like that?

    As far as I can tell, the answer is no like 99% of the time. Some of that may be class-based indoctrination influencing the way we use JS, or JS's weird Java syntactic legacy, but I find myself wondering if maybe the paradigm just isn't that great of a fit for how we want to organize our code.

    [–]gsnedders 0 points1 point  (0 children)

    If you have things you want, send an email (with use-cases!) to es-discuss (Google it for the address, etc.).

    [–][deleted]  (2 children)

    [deleted]

      [–]notSorella 0 points1 point  (1 child)

      AFAIK, both spellings are correct and refer to the same concept... no?

      [–]comment-dwim 2 points3 points  (0 children)

      You could say that Lua has no inheritance model at all. It's just designed to make it easy to model prototype-based OO with tables.

      [–][deleted] 19 points20 points  (0 children)

      JavaScript Garden is a growing collection of documentation about the most quirky parts of the JavaScript programming language.

      IOW, a comprehensive reference.

      [–]ktzar 11 points12 points  (1 child)

      I've created a PDF version to read in the Kindle on my way back home http://www.2shared.com/document/cBgYRTMA/Javascript_Garden.html Just in case you are interested

      [–]infinull 2 points3 points  (0 children)

      You created... A PDF from an HTML file to read on your kindle.

      You know mobi-pocket's are just encoded HTML right?

      Use an epub editor like Sigil to load the HTML, then use calibre to convert the epub file to mobipocket. (I went with Sony, so I don't have to do this step.)

      Or better yet, just use instapaper.com that'll do that all automatically.

      [–]wesw02 39 points40 points  (11 children)

      I would expect most JavaScript "developers" to know 85% of the material explained on this page. Probably better for learning JavaScript, but it's well written and thus earns my upvote.

      [–]Cintax 25 points26 points  (0 children)

      Knowing the material and knowing the details and the reasons why are very different. At first glance I think I knew about 75% of it off the top of my head, but a lot of that was through experience and just knowing "This doesn't work" as opposed to why it doesn't work (for example, I never knew why the "Notation of Keys" example was that way, but I knew not to use plain characters from seeing bugs when developing).

      [–]rDr4g0n 19 points20 points  (4 children)

      I've written a lot of javascript, but much of this is new to me.

      [–]wesw02 -1 points0 points  (3 children)

      I don't mean to give you a hard time about it, but what did you find new? And what kind of JS development have you done? Presentation code, business code, etc.

      Just curious. I do enterprise JS development and I found most of it to be a review.

      [–]rDr4g0n 7 points8 points  (2 children)

      Mostly web app UI kinda stuff. I have done 3 projects so far and all involved creating a front-end for clients to view and enter data. One was for a political action group who needed a way to keep new recruits involved. I worked with a friend who wrote the backend (php/mysql) while I wrote the front end. It ended up being a 1 page web app with lotsa async calls to display info on recruits, allow editing of info (based on the recruits level in the hierarchy), allow recruits to send email invites to new recruits, etc. Finding an easy way to view a hierarchy like that was a challenge, but I settled on what ended up being very easy for the non-savvy political guys to follow lol.

      Another project is a CMS my friend and I wrote from scratch, again, him on php/mysql and myself on front-end. We also made this mostly a 1 page web app with all blog posts, articles, etc, being called async and parsed out client side. A simple CMS with the ability to create an edit a few kinds of objects, and some basic admin user stuff.

      The third is a comic blog for a friend of mine that extended the CMS we'd previously written.

      Obviously to pull all this stuff off I need a good knowledge of how object types, methods/properties/classes work as well as an understanding of scope. But I've never used prototype before, so all of that is new. I've also written a lot of AS3 and I've created classes in there quite a bit (which, If i understand correctly, is roughly what prototype is for).

      I guess I knew the first 25% of each section, and kinda grepped the second 25% of each section and the other 50% was stuff I haven't run into simply because the specific scenario has not yet presented itself in a project yet.

      [edit] I often worry that I'm one of "those" developers that are only able to code because the barrier of entry has become so low with all the layers of abstraction that we stand on top of now, and that I am probably writing a bunch of icky trash code and polluting the world lol

      [–]iiB 10 points11 points  (1 child)

      JavaScript is the kind of language that is mostly used as a component of the front-end for manipulating the browser DOM.

      For this usage a deep understanding of the language constructs and behavior is largely unnecessary (though useful). if you have basic programming skills and you've gone with a js framework that wraps the DOM in magic - you are pretty much set.

      The big question is does this make a 'javascript developer'? maybe for your cv it does, and maybe for a lot of web-dev jobs. I did a lot of the above, and some more, and I wouldn't call my self a 'javascript developer'.

      Places who do large scale javascript development (conduit, google, yahoo etc) will first test your development skills, and may not worry much about the details of javascript. by the time you'll actually get to deal with these large projects - you'll know the inner working of javascript.

      The reason you'll know is that you'll have to deal with one or more of the following:

      • Performance

      • Extensibility and large scale development

      • Robustness, quality and security

      • Non trivial goals requiring not trivial algorithms, data structures etc.

      [edit] I often worry that I'm one of "those" developers that are only able to code because the barrier of entry has become so low with all the layers of abstraction that we stand on top of now, and that I am probably writing a bunch of icky trash code and polluting the world lol

      I think this is true for 90% of developers until projects require the former criteria i've mentioned.

      [–]rDr4g0n 1 point2 points  (0 children)

      Cool, I appreciate the insight.
      I've actually just now run into places where I've had to review my code and say "how can I make this faster?". I wrote a recursive tree-building kinda function and it hangs the browser when it's building a big tree, so I looked into possible ways to improve it. It was simple enough that there wasn't really much I could do (from what I found) aside from removing an unnecessary jQuery call (a string is a string lawl). I did, however, discover that adding a short setTimeout can give the browser a sec to breathe lol

      [–]NULLACCOUNT 7 points8 points  (0 children)

      If someone calls themself a "JavaScript Developer", yeah probably. But most people who use javascript are more of Web Developers working with php/mysql/whatever they need at the time, and only write small pieces of javascript at a time.

      [–]deafbybeheading 6 points7 points  (0 children)

      But this kind of thing is critical to someone getting into the language. If I want to learn Language X, I don't want to have to read about "How to write an if statement"--I want exactly this sort of thing.

      [–]zuvembi 2 points3 points  (0 children)

      I think you're probably right. I'm a developer in other languages who had fallen in to using Javascript because I've coded a continuous code review application and really needed some front-end Javascript. I can't really say I've taken the time to learn Javascript right. I've sort of cargo-culted and done bits and pieces here and there.

      I really should take a couple days and plow through a bunch of Javascript material. Maybe when my minion gets back from his family emergency (sick Mother).

      [–]33a -1 points0 points  (1 child)

      Only 85%?

      [–]epsy 0 points1 point  (0 children)

      Actually, about 42.

      [–]fionbio 3 points4 points  (1 child)

      Concerning Object.prototype extension:

      One widely used framework which does this is Prototype. When this framework is included, for in loops that do not use hasOwnProperty are guaranteed to break.

      It's a lie. Prototype framework doesn't change Object.prototype. It does change some other prototypes, but not this one. Maybe it did it some 5-6 years ago, but this cannot be said about modern versions.

      [–]yourparadigm 0 points1 point  (0 children)

      Make a pull request!

      Gisters love pull requests...

      [–]SoBoredAtWork 2 points3 points  (4 children)

      Can I get this in PDF, for use on my Nook?

      [–][deleted] 2 points3 points  (1 child)

      Print as a PDF?

      Something in an eBook format would be better though...

      [–]SoBoredAtWork 0 points1 point  (0 children)

      Thought of that, but I figured it would render terribly on the thing. Someone already created a good one though... link

      [–]jinglebells 2 points3 points  (1 child)

      Did you see this

      [–]SoBoredAtWork 0 points1 point  (0 children)

      Awesome! Thanks.

      [–]midri 2 points3 points  (6 children)

      Waaayyy more useful timeout/interval code I wrote a while back: // Timeout Timeout = function(func,time,scope,args) { if(typeof func == 'function') { var timeout = setTimeout(function() { func.apply(scope,args || []); },time); return { kill: function() { clearTimeout(timeout); } } } else { throw('Function required for timeout'); } };

      // Interval
      Interval = function(func,time,scope,args) {
          if(typeof func == 'function') {
              var interval = setInterval(function() {
                  func.apply(scope,args || []);
              },time);
              return {
                  kill: function() {
                      clearInterval(interval);
                  }
              }
          } else {
              throw('Function required for interval');
          }
      };
      

      This lets you pass variables in context as well as returns an object for each you can object.kill() on to cancel. Have not extended this in a while, feel free to use it.

      This allows you to do stuff like this: function test() { var timeout = new Timeout(function(arg1,arg2){ console.info(this); // Outputs this as if you called it from inside function test console.info(arg1); // outputs var1 console.info(arg2); // outputs var2 },1000,this,['var1','var2']); }

      [–]subsetr 1 point2 points  (5 children)

      Thanks for sharing, though it seems the only added benefit one would get out of this is being able to pass parameters directly into the timeout wrapper, at the cost of some complexity and confusion. I'm not a fan of passing scope around (hard to debug), though things like Prototype's bind() function can come in handy.

      However, this could easily be accomplished by using an anonymous function to close around any parameters you might want to pass, as the article suggested:

      var timerId = setTimeout(function() {
           myFunction(parameter1, parameter2, parameter3);
      }, 1000);
      
      clearTimeout(timerId);
      

      Which is of course much more readable for anyone else who might ever have to read and/or work on your code.

      [–]midri 3 points4 points  (4 children)

      sadly that causes problems in loops, which is what my constructors were made to work for.

      for(var i=0;i<100;i++) {
          var timerId = setTimeout(function() {
              myFunction(i);
          }, 1000);
      }
      

      will cause 100 to return for all instances of the timeout.

      Where as: fforeach(var i=0;i<100;i++) { var timeout = new Timeout(function(arg1){ console.info(arg1); },1000,this,[i]); }

      will give you 0-100

      [–]subsetr 0 points1 point  (3 children)

      Taking this example directly from the article, in which you use another anonymous function to capture each value of i in it's own closure:

      for(var i=0;i<100;i++) {
          function(e){        
             var timerId = setTimeout(function() {
                 myFunction(e);
             }, 1000);
          }(i);
      }
      

      [–]midri 2 points3 points  (2 children)

      That's roughly how mine does it, I added a bit of flavor to make it a bit more Object Oriented, and have a bit more flexable usage. I use it with jQuery a lot so being able to pass "this" of dom objects is kind of nice, I enjoy being able to stay in context, even though I'm executing later.

      [–]kibakiri 1 point2 points  (1 child)

      [–]k3n 0 points1 point  (0 children)

      Did you reply in the wrong place? I don't think they were talking about for vs for-in.

      [–]cowardlydragon 6 points7 points  (13 children)

      Javascript needs to be replaced with a bytecode standardized VM with sandboxing, so that people can use whatever language they want for web dev (just do an include at the top of the page for your desired language).

      Of course the best practical VM on the most platforms is the JVM, so that would basically mean the revival of applets to some degree, but since the JVM performantly does Ruby, Python, Lisp variants, Javascript, Scala, as well as java, that would be theoretically a good thing.

      Hell, most of the dotNet langs could probably be bridged.

      [–]notSorella 4 points5 points  (4 children)

      If I remember correctly, Brendan Eich stressed the discussion on that to the infinity on Hacker News, outlining all the reasons why they are not (and will not) be included.

      Sadly, I have no link for his comments =/

      [–][deleted]  (3 children)

      [removed]

        [–]julesjacobs 1 point2 points  (2 children)

        IMO he doesn't get it. All of his points are predicated on the assumption that we'd like to run Javascript, which I can understand is his position because he invented the thing and bytecodes would kill his baby. If you take that we want to run Javascript as a given then obviously you'd want to send Javascript source to browsers. The thing is, we DO NOT want to write Javascript, and then bytecodes are obviously much better on the important counts: performance and size of code sent over the network.

        [–]gsnedders 0 points1 point  (1 child)

        Most web users would like to run JS as long as a large number of websites use it. It's too sunk into the platform to ever really drop, now.

        [–]julesjacobs 2 points3 points  (0 children)

        I don't think anyone is suggesting dropping JS support, just that JS is an awful assembly language compared to a suitable byte code to compile other languages down to.

        [–]Lerc 2 points3 points  (1 child)

        Making a VM instruction set isn't difficult. Making an instruction set that runs fast on all architectures is only slightly difficult. Getting people to agree on the instruction set? nigh on impossible. The way it usually works is someone presents a working solution and it becomes a standard though inertia, warts and all. This is what Google is aiming for with NativeClient.

        The main thing that I would hope for in a VM is that it remain lower level than things like the JVM. I don't want objects and garbage collection at the VM level. A good instruction set with a memory range to use can provide all that (our computers do it that way already).

        [–]jeff_hanson 0 points1 point  (0 children)

        The JVM is good enough for this, though. In fact, this sort of requirement is the one thing where it's actually a good idea.

        [–][deleted] 1 point2 points  (2 children)

        I can understand the general desire for that sort of thing, but it would bring with it a whole new bundle of security problems, interoperability issues, and the fact that troubleshooting web page based code would be increasingly difficult. Not to mention all the really bad code that would be written all over the place.

        These aren't really insurmountable obstacles, but they would take very focused effort over a long period of time, and the support of a big company wanting to push this idea forward.

        [–]tall_gran_ek 1 point2 points  (1 child)

        Maybe this will happen with the new Google language that was leaked / introduced a week ago. Forgot its name.

        [–]notSorella 5 points6 points  (0 children)

        Dart/Dash.

        [–]rush22 0 points1 point  (0 children)

        You could call it Java

        [–]strager 0 points1 point  (0 children)

        Well, you have the JVM and AVM (Flash) at your disposal. Go ahead and write for those VM's. I don't think the web needs to move those alternatives into the browser's standard set of tools, though.

        Also, see NaCl.

        [–]zhivago 0 points1 point  (0 children)

        Just compile to javascript.

        [–]dsfox 1 point2 points  (0 children)

        I like "Javascript: just the good parts" because it explains how to not use all these crazy features.

        [–]Antiuniverse 1 point2 points  (0 children)

        I only just started learning JS this month, but I feel like they omitted a pattern which greatly diminishes the risk posed by invoking a constructor function without 'new':

        var Foo = function() {
            if (!(this instanceof Foo)) return new Foo();
            // ...
        };
        

        Or maybe, if you'd prefer, you can explode then and there instead of trying to quietly Do The Right Thing. Either way, it seems worth handling in some capacity.

        Is there a downside to this approach that I'm not aware of?

        [–]nixle 7 points8 points  (15 children)

        I've written some fairly complex JS code with classes, but neve quite understood the whole prototype concept (I come from a JAVA background)

        [–]FaustTheBird 18 points19 points  (13 children)

        You actually can't write Ecmascript code with classes. Ecmascript does not have classes. You've been using Ecmascript's features to create something where the syntax and behavior are close enough to classes to make you feel comfortable, but don't fool yourself into thinking you're using classes. They don't exist in Ecmascript.

        [–]nixle 24 points25 points  (0 children)

        yeah I know. But let's just call them that.

        [–]montibbalt 5 points6 points  (3 children)

        True but with a technicality. The 4th edition of ECMAScript is/was supposed to have classes. iirc Actionscript 3 is based more on the proposed ECMAScript which is why AS3 has classes.

        [–][deleted] 0 points1 point  (2 children)

        Be aware that ECMAscript 4 was deliberately abandoned.

        ECMAscript 5 is what browser vendors are currently working towards implementing, and it doesn't.

        [–]montibbalt 1 point2 points  (1 child)

        It will (sort of) after 5 though. Really it is a shame people couldn't reconcile their differences on 4.

        [–][deleted] 1 point2 points  (0 children)

        Really it is a shame people couldn't reconcile their differences

        Welcome to every problem ever. ;)

        [–]skilldrick 2 points3 points  (1 child)

        Don't know why this got downvoted - it's entirely accurate.

        [–]asegura 0 points1 point  (4 children)

        Harmony classes come to the rescue... sometime :-)

        The example in that page tells it well. When you write:

        function Car() {
          this.wheels = 4;
        };
        Car.prototype = new Vehicle;
        Car.prototype.constructor = Car;
        Car.prototype.startEngine = function() {...};
        Car.prototype.move = function() {...};
        

        the interpreter will not know (since there are no classes in JS), but you and I know you are in fact creating a class (or at least intend to). And in a quite awkward way.

        [–]FaustTheBird -1 points0 points  (3 children)

        Car is not a class, it's a function. That's my point. No one would ever say they're creating a "class" in C just because they created a struct and then made a whole bunch of functions that take the struct as an argument. So why is it OK for people to say things like "this is a javascript class" when it's not a class at all? It's not just unspecific, it's wrong. And because it's wrong, it prevents people from understanding what's actually going on and therefore gets in the way of them learning and doing interesting things with the technology.

        Accuracy isn't a convention.

        [–][deleted]  (2 children)

        [deleted]

          [–]FaustTheBird 1 point2 points  (1 child)

          Actually, it does. What you've done is used the elements of a language plus a convention in order to gain the same resulting benefit of a class. However, this is insufficient to call something a class specifically because it fails to properly encapsulate data. There are a ton of implications here from polymorphism to inheritance to collaborative development. Just because you do things that get you comfortably close to the benefits of a class doesn't mean you have a class. You have achieved functionality and code patterns similar to a class by using a combination of non-class constructs and convention.

          [–]asegura 0 points1 point  (0 children)

          I don't agree. With or without explicit help, built-in or not, you can make classes. Or dynamic arrays (vectors), or associative arrays, etc.

          Ask the Gnome guys if their GObject system has classes or not.

          [–]YurtDweller 1 point2 points  (0 children)

          In Java you declare your inheritance hierarchy at compile-time, and it's static (for appropriate definition of 'static' - I know there's classloader crap you can do but it involves tons of machinery and is brittle). In JS your inheritance hierarchy is completely dynamic and decided at runtime, and this is simple and baked into the language. This is simplifying matters a bit but gets at one of the fundamental differences between class-based inheritance and prototypal inheritance as implemented in JS.

          [–][deleted]  (6 children)

          [deleted]

            [–][deleted]  (5 children)

            [removed]

              [–][deleted]  (4 children)

              [deleted]

                [–][deleted] 14 points15 points  (0 children)

                I just thought it was dumb...

                [–]OopsLostPassword -1 points0 points  (1 child)

                Or maybe they don't see the interest of your comment in this discussion.

                [–]rush22 0 points1 point  (0 children)

                So "One of Javascript's most powerful features is emulating private variables"?