Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Is this a method?

  • This topic is empty.
Viewing 15 posts - 16 through 30 (of 32 total)
  • Author
    Posts
  • #179138
    nixnerd
    Participant

    Holy shit that was informative. @alenabdula… drop that mind blown gif on this thread… so fitting.

    #179139
    nixnerd
    Participant

    Guys… how can I learn the ways of super clean OOP? Whenever I try to implement it myself… I’m wrong. I’m specifically looking for JS OOP instruction. Any good resources?

    I want to be able to achieve MAXIMUM code re-usability. Right now… a lot of my JS can’t really be taken apart without some adapting.

    #179144
    __
    Participant

    Here it is implemented in a slightly different way.
    @JacobPeters

    Cool, I like it. I’ve been writing everything in the “function expression” form lately because I’ve been doing a lot of Node and that’s more-or-less what require expects.

    Only two things I would change:

    • I would define the regexes “in place,” so I don’t have to pass them through the constructor. That seems inconvenient …unless you’re doing it for a specific reason which I have overlooked.
    • Depending on desired browser compatibility, I wouldn’t “use strict”. Yes, non-supporting browsers simply ignore it, but you have to stay within the intersection of strict and non-strict rules anyway (unless you don’t mind non-strict browsers crashing). As a rule, and for browsers (I love Node), I stay inside that intersection, and I don’t “use strict” simply as a reminder of this restriction.

    The fact that javascript is dynamically typed and functions look the same as variables in the implementation is completely orthogonal to the discussion of whether methods can or cannot exist in a language.

    I’m happy calling them “methods.” Semantically, yes, they are methods. I totally agree. While the details of the implementation don’t change that fact, they quickly become relevant in certain situations. For example, this whole ambiguity stems from the fact that functions in JS are first-class, which has a huge impact on how js code is (can be) written.


    @Joe_Temp
    :

    Douglas Crockford: Function the Ultimate

    particularly relevant parts at 0, 25, 50 and 52 minutes.

    Watch it, take a break. Watch it again, but this time you can pause to look at the code examples when needed. Watch it again tomorrow.

    #179185
    Alen
    Participant
    #179187
    JacobPeters
    Participant

    I would define the regexes “in place,” so I don’t have to pass them through the constructor. That seems inconvenient …unless you’re doing it for a specific reason which I have overlooked.

    There was a purpose. I was thinking about making it so rules could be dynamically added to the validator. I abandoned the idea last night but had already started that direction. I took a little bit of time today and implemented it. It should be more reusable now.

    http://codepen.io/jacobcpeters/pen/qAILc?editors=001

    Depending on desired browser compatibility, I wouldn’t “use strict”.

    Crockford, Zakas, and Resig all recommend using it, it’s almost completely backwards compatible, and it’s really is helpful when it errors on undefined this.

    #179199
    __
    Participant

    There was a purpose. I was thinking about making it so rules could be dynamically added to the validator.

    I see. I had that idea in mind when I wrote mine, as well, which is why the “rules” methods are all on the returned object instead of being private.

    Crockford, Zakas, and Resig all recommend using it, it’s almost completely backwards compatible, and it’s really is helpful when it errors on undefined this.

    mm… Have you ever encountered problems with relying on “strict” code in non-supporting browsers? I have been wary about it because of cautions (from MDN and elsewhere) about “blindly” relying on strict mode.

    edit
    Also, to clarify, I write strict mode, I just leave the statement out when deploying.


    @AlenAbdula
    that’s exactly the video I was looking for last night (although I am opposed to the upcoming “syntactic sugar” which tries to make JS look like it actually uses classical inheritance).

    #179206
    nixnerd
    Participant

    So much great stuff.


    @traq
    , what’s the best resource you’ve found for node? Did you ever try that CLI tutorial?

    #179214
    __
    Participant

    what’s the best resource you’ve found for node?

    documentation.
    Unfortunately (for you), I’m not much of a “tutorial” person.

    I don’t remember much about the cli tutorial we were talking about. I tried it, but I don’t think I stuck with it long. I just installed node instead.

    #179238
    Alen
    Participant

    I just installed node instead.

    I’m the same way, for some reason I just can not follow tutorials. I just go docs or source.

    #179240
    __
    Participant

    I just go docs or source.

    01110111 
    01101111 
    01110010 
    01100100 
    00101110
    
    #179242
    nixnerd
    Participant

    I need practical examples so I can understand the implications of what I just learned. But… Linux is one thing I don’t read tuts on. NO ONE has the same exact setup as me… so they’re useless.

    You know… I kind of hate to say this but jQuery has awesome docs. Are Node’s that good? If so… I’ll just read them.

    #179243
    nixnerd
    Participant

    I kind of hate to say this but jQuery has awesome docs. Are Node’s that good?

    It does not look like it. I love those docs because they tell you about the property/tool in question and give examples as to how you might write/use it. I’m definitely a fan.

    #179247
    __
    Participant

    no, node docs don’t generally have example code with them. and some of it is incomplete…

    #179257
    Alen
    Participant

    #180039
    dyr
    Participant

    A couple general tips for improving code re-use:

    1. De-couple as much code as possible from the DOM (since this type of code generally is tightly coupled to the structure of the document)
    2. Investigate function composition
    3. Learn about javascript mixins

    Good luck in your endeavors!

Viewing 15 posts - 16 through 30 (of 32 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.