www.webdeveloper.com
Results 1 to 5 of 5

Thread: JavaScript Classes, Modules, etc.

  1. #1
    Join Date
    May 2012
    Location
    St. Helens, UK
    Posts
    74

    JavaScript Classes, Modules, etc.

    Hi all,

    I'm currently in the process of working my way through the 6th edition of JavaScript: The Definitive Guide; basically, my current project is to learn JavaScript properly, esoteric features and all. It's going okay, I'm enjoying it for the most part, although I'd be lying if I said it wasn't difficult in places - the chapter on Classes and Modules in particular is quite difficult to grasp on a first reading.

    I'm pretty confident that I'll get it eventually, so I'm intending to work through the rest of the book and return to the tricky bits later, in the hope that it'll make more sense at a later date. Anyway, I was just wondering: how many of you tend to actually use features such as prototypal inheritance and so forth often? Just curious.

    At the moment, I keep finding myself suspecting that the vast majority of JavaScript users probably only use the relatively straightforward, self-explanatory aspects of it. (I guess part of me is wondering whether putting the effort into learning the difficult bits is worth it.)

    Cheers!

  2. #2
    Join Date
    Jul 2003
    Location
    The City of Roses
    Posts
    2,503
    Quote Originally Posted by daihuws View Post
    At the moment, I keep finding myself suspecting that the vast majority of JavaScript users probably only use the relatively straightforward, self-explanatory aspects of it.
    I think that's probably right. Mostly you'll only need to use JavaScript's inheritance if you're creating a reusable library or if you're building a rich, desktop-like application.

    Quote Originally Posted by daihuws View Post
    I guess part of me is wondering whether putting the effort into learning the difficult bits is worth it.
    That depends partly on the kind work you do on a day-to-day basis, and partly on how satisfied you are with your currently level of knowledge and skill. Personally, I get a sense of satisfaction from understanding the difficult bits, even if I don't get many opportunities to put it to use at work.
    for(split(//,'))*))91:+9.*4:1A1+9,1))2*:..)))2*:31.-1)4131)1))2*:3)"'))
    {for(ord){$i+=$_&7;grep(vec($s,$i++,1)=1,1..($_>>3)-4);}}print"$s\n";

  3. #3
    Join Date
    May 2012
    Location
    St. Helens, UK
    Posts
    74
    Hi, cheers for feedback.

    That depends partly on the kind work you do on a day-to-day basis, and partly on how satisfied you are with your currently level of knowledge and skill. Personally, I get a sense of satisfaction from understanding the difficult bits, even if I don't get many opportunities to put it to use at work.
    Me too; I enjoy learning new things for the sake of learning them, much of the time. An advanced knowledge of JavaScript isn't something I feel like I really need at the moment, but I've got something of an itch to try and understand it. (And I quite often find that once you've learned how to do something you tend to find ways of using it that you hadn't predicted...)

  4. #4
    Join Date
    Sep 2011
    Location
    Bristol, England, United Kingdom
    Posts
    192
    To be honest JavaScript is an easy language to grasp once you've had some experience. Learning the more advanced features won't take long, especially since you're limited to the number of things you can do in the browser anyway (i.e., there is no general-purpose scripting as far as JS is concerned).

    But I'll echo Jeff's sentiments; you're probably not going to use many advanced features of the language for your average, run-of-the-mill website. JavaScript apps are something else, though. Building a browser-based JavaScript game could be a little more daunting than simple form control or on-page interactivity. Generally I find it's the methodologies and principles behind the results that are the more tricky parts to learn. For example, writing a function for a game engine that clips out of range objects. You can bet your life you're going to understand it once you've been presented with the code, but can you write that code yourself?

    Learning the language is one thing, using it is another.

    As with any of life's endeavours, I suppose the question to ask yourself is what you want to achieve? There's no need to learn for learning's sake if you have no intentions of actually using your knowledge, that constitutes a waste of time and effort that could be better spent on other projects. I say learn what you need as and when you need it.

  5. #5
    Join Date
    Feb 2003
    Location
    Michigan, USA
    Posts
    5,773
    Object oriented JavaScript is useful even for simple things. Writing modular and reusable code is always a good idea --- even if all you are doing is processing a form submit, running some validations, and firing off an Ajax request.

    And if you want to make inheritance and modules more intuitive to use, try this out:

    https://github.com/gburghardt/JsLib/...es/Function.js

    This allows for defining JavaScript "classes" like:

    Code:
    ChildClass = ParentClass.extend({
    
      includes: [Mixin1, Mixin2],
    
      self: {
        // class level methods
      },
    
      prototype: {
        // instance methods
      }
    
    });
    This supports:

    * True prototypal inheritance
    * Mixins ala Ruby
    * Inheritance of instance and class methods

    Plus, you can dynamically include mixins:

    Code:
    var Mixin = {
      self: {
        // class level methods
      },
      prototype: {
        // instance level methods
      }
    };
    
    SomeClass.include(Mixin);
    Check out the specs for more info: https://github.com/gburghardt/JsLib/...nction.spec.js

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles