As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
What javascript OOP frameworks do you use?
I need a library to emulate Javascript OOP programming with constructors, members, properties(public, private), inheritance
Thanks for your answer
Javascript is fully Object Oriented Language, if you didn't know it yet, it means you don't know it well enough. Though some concepts differ from e.g. JAVA, or C# (like inheritance, encapsulation & etc.) they can be successfully simulated (using prototype chaining, closures & etc.).
take a better look at language and you'll find out that no additional emulating is needed to implement OOP behavior in it.
Check out the Prototype framework,
Featuring a unique, easy-to-use
toolkit for class-driven development
and the nicest Ajax library around,
Prototype is quickly becoming the
codebase of choice for web application
developers everywhere
You may use Coffee Script, a language that 'compiles' to JavaScript.
JavaScript is not an explicit object oriented language. But you can use it to implement all the Object oriented ideas if you know it well. I would suggest looking at following w.r.t JavaScript programming:
Defining custom objects in JS. This is done in a manner very much similar to "function" definition, that is where most beginners stumble.
Difference between Function invocation and Constructor style invocation (latter is used in creating objects)
Assigning member variables to objects. This can be achieved by using "this" keyword in the function definition(will be clear if point 2 is clear). Also "prototype" can be used for the same purpose.
Having private variables in an object: This can be achieved by using "var" keyword for variables declared inside the function (Will be clear if point no 2 is clear).
This site is a very good source to start you off with these concepts:
http://javascript.crockford.com/
Related
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I want to learn Node.js. I'm sure, I will need good experience in Javascript (OOP). Is there any other technology i should know about to learn it? And also how long will it take me to starting implementing node.js taking into account i have decent experience in Javascript?
Thank You
http://www.crockford.com/javascript/inheritance.html
JavaScript is a class-free, object-oriented language, and as such, it
uses prototypal inheritance instead of classical inheritance. This can
be puzzling to programmers trained in conventional object-oriented
languages like C++ and Java. JavaScript's prototypal inheritance has
more expressive power than classical inheritance, as we will see
presently.
Javascript and Java are two different beasts.
I have been writing JavaScript for 8 years now, and I have never once
found need to use an uber function. The super idea is fairly important
in the classical pattern, but it appears to be unnecessary in the
prototypal and functional patterns. I now see my early attempts to
support the classical model in JavaScript as a mistake.
Some things I think you should look into.
Testing your code thoroughly with framework like for example mocha is very important.
learn npm to publish your own modules and to search for other modules.
A database like for example mysql, mongodb or redis and how to use them in node.js. I pesonally really like redis client library for it's insane speed.
Git(hub) to put your code into a repository(SCM).
Except from all kind of JavaScript programming experiences (OOP is not required) and depending from your former programming skills it also helpful to have a basic knowledge of:
the Posix API (what are file descriptors? what are pipes?)
what is HTTP? How does HTTP work?
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I read somewhere that using prototype to extend native objects (String, Number, Array, etc.) was a bad idea. Is this true? Why or why not?
I don't think it's bad. If you have a look at Ruby on Rails, very many native objects are extended with custom functionality and it's a very good framework.
What would be bad is if you change existing methods on native objects. this could cause unforseen consequences.
There's a great discussion about this in this video from JSConf 2011 by Andrew Dupont. http://blip.tv/jsconf/jsconf2011-andrew-dupont-everything-is-permitted-extending-built-ins-5211542
Basically the points are:
Don't extend Object.prototype
Some people might like to extend things, some people don't
You need to know what you're doing
Don't use two libraries that extend things, because it can be bad
Extending prototypes to add standard functionality is almost always ok.
I would stay clear of extending/modifying behavior of native objects.
It at least makes sense when developing in a team environment.
Simply because, months later, another developer writing another independent piece of code isn't immediately going to recognize the changed behavior unless documented somewhere and made aware of it prior to starting his task.
Instead, I suggest encapsulating/"namespace"-ing all such functionality such that somebody may chose to or not to use the modified functions.
Also, native objects and their methods are thoroughly tested for wide-ranging cases. So you you'd have to be completely sure of what you're doing before modifying native functionality.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
I'm wondering if such a library exists, where the library contains only a collection of common utility functions such as trim, indexOf (for arrays), map, each, typeOf and so on...
I'm aware that jQuery provides some of the functions I listed above, but I'm looking for something that is designed purely for this (I really don't need jQuery on the server-side running node.js for instance, nor do I want to depend on it if I'm writing a non-jQuery-related JavaScript library). I've recently begun collecting an assortment of these functions for future copy/pasting, but my guess is that there are many others that I won't even know to look for, or think of using, unless someone presents them to me.
I'm fond of underscore.js; it doesn't provide string utilities such as trim; it's focused on object-oriented and functional utilities, including all of the other things you mention. Another nice thing about it is that it doesn't reference the DOM at all, so it's useful for javascript programming that isn't web-based or DOM related.
The functions you mention are all standard in ECMAScript 5. And this library implements them in such a way that you can use them in older browsers/JavaScript versions as well, in a way that will be compatible when your environment catches up with the standard:
https://github.com/kriskowal/es5-shim/blob/master/es5-shim.js
Boiler.js is an up and coming utility library that offers many useful JavaScript utilities and is a direct competitor with Underscore.js.
jQuery provides all of those and many more, you would be better off just using it.
jQuery can sit side-by-side with other frameworks, so can be independent if another framework is present.
See: jQuery Utilities Documentation
Javascript itself has many of these functions built into the basic types. Before building your own, perhaps a copy of JavaScript: The Definitive Guide, focusing on the API reference in the back, would do you some solid good.
After that investigate frameworks, or at least being looking into how you can create your own framework for your functions (as opposed to copying and pasting). Here the module pattern would be helpful to you.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I come from a C/Unix background, with a lot of experience in shell scripting, and some on Perl, elisp, etc. too. But now I'm getting into some work where I'll need to be developing interactive web-based interfaces, and I need to learn JavaScript. My problem is that all the resources I've found online for learning JavaScript seem to be targeted at an audience who's never programmed, and their authors don't seem much better. As soon as I see "validating user input to take the load off your server" as one of the great uses for JS, I want to scream and I feel like I can't trust anything else the author says. ;-)
Can anyone recommend good resources for an experienced programmer wanting to learn JS as a new language? Ideally I'd like to get started online, but dead tree recommendations would be welcome too, especially if I can preview them online.
A great JavaScript book for experienced programmers is Doug Crockford's JavaScript: The Good Parts. It's short, assumes you know what you're doing, is opinionated, and is not a tutorial.
My advice: Forget what you know about object oriented programming. Attempts to apply the inheritance paradigms from an OO language have repeatedly overcomplicated many, many chunks of JS code.
Prototyping is not Class construction. Object instantiation is not Class instantiation. "Classes" are not real.
There are ways to get what you want. You can even have something akin to privates - but they are not methods or members. They are merely locally scoped. Inheritance is often faked, but with mixed results, and universally at the expense of data hiding.
Javascript is prototyped. It is not object oriented. Keep that in mind every time you think something like, "Man, an interface here would be awesome..."
https://stackoverflow.com/questions/3655530/best-javascript-book-for-an-experienced-coder/3655693#3655693
https://stackoverflow.com/questions/1594159/best-book-to-learn-web-development-for-a-professional-developer
https://stackoverflow.com/questions/74884/good-javascript-books
but I will recommend these two fantastic books, which teach me a lot.
Take a look at Eloquent JavaScript. It doesn't cover everything, but it will move you towards idiomatic JavaScript programming -- things like functional programming, closures and prototypes. (The online version comes complete with a sandbox tutorial environment.) The rest, after all, is just knowing how to use references.
Javascript Guide from Mozilla Developer Network, a simple and yet informative guide, gives beginners a big picture of JS in a short time.
https://developer.mozilla.org/en/JavaScript/Guide
JavaScript: the definitive guide is one of my favorite programming books:
http://oreilly.com/catalog/9780596101992
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
In JavaScript what sort of inheritance do you favour? The ECMA standard is to use prototype chaining. So I just set the prototype of the object that's doing the inheriting (monkey) to invoke a new instance of the object I want to inherit from (animal):
monkey.prototype = new animal();
I am aware there are other ways to achieve inheritance. i.e inheriting only the prototype, parasitic inheritance, deep copy, shallow copy.
Can anyone enlighten me and tell me if there is one in particular I should use? One that has benefits that outweigh the other methods.
Theres a lot better article on it here than I could ever write. http://www.crockford.com/javascript/inheritance.html
In general it depends on what you want to achieve. In general though I think duck typing is what is considered best for javascript.
I posted an article that talks about the in and outs of JS inheritance. It's relevant if you're trying to emulate class based inheritance. I don't like Douglas Crockford's approach that tries to stay away from the new keyword. I learned class based inheritance with C++ and Java and find it much easier to think about http://js-bits.blogspot.com/2010/08/javascript-inheritance-done-right.html