Home › Forums › JavaScript › Is this a method?
- This topic is empty.
-
AuthorPosts
-
August 14, 2014 at 8:57 pm #179138
nixnerd
ParticipantHoly shit that was informative. @alenabdula… drop that mind blown gif on this thread… so fitting.
August 14, 2014 at 8:59 pm #179139nixnerd
ParticipantGuys… 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.
August 14, 2014 at 9:55 pm #179144__
ParticipantHere it is implemented in a slightly different way.
— @JacobPetersCool, 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.
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.
August 15, 2014 at 8:52 am #179185Alen
ParticipantAugust 15, 2014 at 9:13 am #179187JacobPeters
ParticipantI 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
.August 15, 2014 at 10:26 am #179199__
ParticipantThere 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).August 15, 2014 at 11:06 am #179206nixnerd
ParticipantSo much great stuff.
@traq, what’s the best resource you’ve found for node? Did you ever try that CLI tutorial?August 15, 2014 at 11:25 am #179214__
Participantwhat’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.
August 15, 2014 at 6:44 pm #179238Alen
ParticipantI just installed node instead.
I’m the same way, for some reason I just can not follow tutorials. I just go docs or source.
August 15, 2014 at 7:17 pm #179240__
ParticipantI just go docs or source.
01110111 01101111 01110010 01100100 00101110
August 15, 2014 at 7:24 pm #179242nixnerd
ParticipantI 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.
August 15, 2014 at 7:27 pm #179243nixnerd
ParticipantI 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.
August 15, 2014 at 9:49 pm #179247__
Participantno, node docs don’t generally have example code with them. and some of it is incomplete…
August 16, 2014 at 4:06 am #179257Alen
ParticipantAugust 20, 2014 at 2:17 pm #180039dyr
ParticipantA couple general tips for improving code re-use:
- 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)
- Investigate function composition
- Learn about javascript mixins
Good luck in your endeavors!
-
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.