JavaScript tips and tricks (4)

For the last article of this series, I’ll let Douglas Crockford do the talk :) This is an amazing video about the good and the bad parts of JavaScript, as seen by a guy that seriously, seriously knows his stuff: Douglas works in the YUI team at Yahoo!, and has written a lot about JavaScript: he coined the phrase about JavaScript being the world’s most misunderstood language, and wrote the amazing JSLint tool.

I the video below, Douglas exposes all his thoughts about the language, both the good and the evil, all out of his own experience as a guy who had to rediscover JavaScript in 2000. Really interesting stuff!

JavaScript tips and tricks (3)

How to organize code in “namespaces”

When you use lots of libraries in your code, you can easily pick up a function name that corresponds to a pre-existing name in some library that you might have included. To avoid that, you should create namespaces that encapsulate the code of your application:

[source:javascript] var net = { kosmaczewski: { adrian: { blog: { articles: {}, images: {}, snippents: {}, tutorials: {}, rants: {} } } } };

// Shortcut (for performance purposes) var blog = net.kosmaczewski.adrian.blog; [/source] Continue reading

JavaScript tips and tricks (2)

Object-Oriented Programming in JavaScript

Functions are also used to represent classes when doing object-oriented JavaScript. There are several possible ways to write object-oriented JavaScript code, but they all turn around the concept of the “Function” class:

[source:javascript] function Thing() { var privateField = “PRIVATE”; var self = this; // See below for more explanations about “this” :)

var privateMethod = function() {
    alert('Private methods can be called from public methods');
    self.anotherPublicMethod();
}
this.publicField = "PUBLIC";
this.publicMethod = function() {
    privateMethod();
    alert('From the public method;\nthis is a public value: ' + this.publicField +
    '\nand this is a private value: ' + privateField);
};
this.anotherPublicMethod = function() {
    alert('You need a trick to call this from a private method!');
};

}

// Creating a new instance of “Thing” var thingy = new Thing(); thingy.publicMethod(); // you can also call thingy“publicMethod”; [/source] Continue reading

JavaScript tips and tricks (1)

JavaScript As I said yesterday, JavaScript is the world’s most misunderstood language, which means that you must unlearn what you have learned. However complicated it might seem at first, it is quite easy to write and understand the most complex of JavaScript codes with just some examples.

Just a few observations before starting:

  • Semicolons (;) are not mandatory, but strongly recommended!
  • You can create strings using either ‘apostrophes’ or “quotes”. “You can also ‘mix them’ as you want”, but ‘always keeping the “order” when using them’.
  • Always use the “var” keyword when defining variables. Otherwise, the variables will be created on the “Global Object” of JavaScript, and this is a bad thing(TM): variables created in the “Global Object” do not get garbage collected!

Continue reading

Web Development == Software Development?

Introduction

I have been developing web applications since 1996, and I still do a fairly large amount of web development nowadays. During these years I have seen some common misconceptions and myths about web development, that ultimately have a direct impact in the usability of the system. I will outline these in this article, providing at the end my opinion on how to achieve a proper QA process.

Web 2.0 Continue reading