Today's Question:  What does your personal desk look like?        GIVE A SHOUT

 JAVASCRIPT


  Commonly used AJAX frameworks

Have you ever wondered to design your website like desktop applications? Fortunately, with AJAX we can achieve this. By using AJAX, we no need to refresh the whole page when we just want to update a portion of a website such as the weather information or news panel. This makes our web apps look like desktop applications and bring good user experience to our visitors. You can create an XMLHttpRequest object every time when you want to initialize an AJAX call, unfortunately you may need repeat every step every time, this is time consuming and brings maintenance overhead. Do you know what kind of...

4,874 0       AJAX JQUERY FRAMEWORK DOJO YUI


  Update parent window after closing the window opened by window.open()

Imagine we have a webpage which has a text field to let user enter a date. Usually, we may create a calendar window to ask the user to pick one date from the calendar window, when the date is picked, the calendar window will close and the date picked will be put into the text field. This way involves the window.open() method in JavaScript, and we may think how the opened window knows its parent window and then updates the parent window. I give a simple demo on this.We have two pages, on is the page which will trigger to open a new browser window, the other one is the page displayed in the open...

8,345 0       UPDATE WINDOW.OPEN JAVASCRIPT RETURN VALUE


  Get hostname from a URL using JavaScript

Sometimes we may have strings which contain some UR;s and we may want to retrieve the hostname from the URLs for some statistic use. For example, we may have a URL : http://www.example.com/aboutus.html. We may want to retrieve the www.example.com from the URL. How? Use regular expression. Here I give an example using JavaScript. If you want to check whether a string is a URL or not. Refer to Detect URLs in a Block of Text. In JavaScript, we can have a regular expression like var pattern=/(.+:\/\/)?([^\/]+)(\/.*)*/i;the regular expression pattern can be used to get the hostname. There are three...

18,529 0       JAVASCRIPT REGULAR EXPRESSION URL HOSTNAME


  var in JavaScript

Geoff published an article sometime ago--"How one missing var ruined our launch". This article described one case where MelonCard uses Node.js as their backend system, suddenly there was a small registration peak period--50-100 people registered concurrently, then the entire website stopped responding and many other strange problems showed up. When they were investigating the source of the problem, they found one missing var in the following code.app.all(‘/apps/:user_id/status’, function(req, res, next) {    // …    initial = extractVa...

3,366 0       JAVASCRIPT VARIABLE SCOPE


  Create namespace in JavaScript

A namespace (sometimes also called a name scope) is an abstract container or environment created to hold a logical grouping of unique identifiers or symbols (i.e., names). An identifier defined in a namespace is associated only with that namespace. The same identifier can be independently defined in multiple namespaces. That is, the meaning associated with an identifier defined in one namespace may or may not have the same meaning as the same identifier defined in another namespace. Languages that support namespaces specify the rules that determine to which namespace an identifier (not its def...

5,593 0       JAVASCRIPT EXAMPLE NAMESPACE


  this in JavaScript

this is a keyword in JavaScript. It refers to an internal object created automatically when a function executes, it can only be used in a function. For example:        function test(){    this.x = 1;  }The this keyword will change when a function is called in different situations. However, the general rule is : this refers to the object which calls the function.Next we discuss the use of this in 4 different situations.1. In pure function callThis is the most common use of a function, it is a global call, so the this w...

5,748 0       JAVASCRIPT THIS KEYWORD USE


  Why you should be careful about optimizations

In one of my current javascript projects, I have to deal with 3D voxel coordinates. And, sometimes, I have floating points coordinates which must be converted to integers in order to convert them into proper array index.Javascript is a wonderful language, really. However, implementations are sometimes weird, and the way to do something can sometimes have very huge impacts on the performances. Worse, sometimes the classical way is more expensive than the tricky one.So, some people have made performance comparisons on jsperf to check which is the fastest way to do. Most of these tests sa...

3,350 0       JAVASCRIPT OPTIMIZATION TRICK BITWISE FLOOR


  JavaScript: Private variables

The first thing you often hear when talking about JavaScript is often “JavaScript doesn’t have visibility modifiers, hence it doesn’t support private variables”. This is only valid for 50%, because JavaScript indeed doesn’t have visibility modifiers (public, private, friend) but it has closures and function scopes. With these tools we can make variables private. Let’s take the following function:var names = ["Kenneth", "John", "Marc", "Robert"];var lookup = function (index) { return names[index];}alert(lookup(0));As you can see the variable “names&r...

4,504 3       JAVASCRIPT PRIVATE VARIABLE CLOSURE