Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to use Javascript's "good parts"

On Stackers' recommendation, I have been reading Crockford's excellent Javascript: The Good Parts.

It's a great book, but since so much of it is devoted to describing the best way to use Javascript's basic functionality, I'm not sure how I can put his advice into practice without duplicating the efforts of many other Javascript programmers.

Take this passage, for example:

When you make a new object, you can select the object that should be its prototype. The mechanism that Javascript provides to do this is messy and complex, but it can be significantly simplified. We will add a create method to the Object function. The create method creates a new object that uses an old object as its prototype.

if (typeof Object.create !== 'function') {
 Object.create = function(o) {
  var F = function () {};
  F.prototype = o;
  return new F();
}

I could manually add this code to all my Javascript projects, but keeping track of everything would be a huge pain.

Are there any libraries that implement The Good Part's recommendations and thereby save me the trouble of having to keep track of them (/ physically type them all out)?

like image 842
Tom Lehman Avatar asked Dec 14 '08 19:12

Tom Lehman


People also ask

Is JavaScript a Good language?

1) It's the most popular programming language We start our list with possibly the most significant reason! According to Stackoverflow.com, JavaScript is the most popular programming language used by professional developers today. Even back-end developers choose JavaScript more often than not.

Is JavaScript a scripting language?

JavaScript (often shortened to JS) is a lightweight, interpreted, object-oriented language with first-class functions, and is best known as the scripting language for Web pages, but it's used in many non-browser environments as well.

How does JavaScript work?

The source code is passed through a program called a compiler, which translates it into bytecode that the machine understands and can execute. In contrast, JavaScript has no compilation step. Instead, an interpreter in the browser reads over the JavaScript code, interprets each line, and runs it.


1 Answers

Prototype has many great features, including a Class helper that handles the details of JS "inheritance" via the object prototype.

Edit: damn, I keep forgetting that jQuery (my own library of choice) has jQuery.extend

like image 156
Tautologistics Avatar answered Sep 20 '22 05:09

Tautologistics