Archive for javascript

Mistakes On Chain Assignment In javascript

Sep 30, 2011 No Comments by Mahdi Pedram

One common mistake that I see developers do is exposing a variable to the Global object in chain assignment.
first I let’s see how can you expose a variable to the Global object by accident.
 
function test(){
a =12; // var is missing
return a;
}
test();
 
By missing the keyword var even though variable a is inside of the function but [...]

javascript Read more

Removing elements from an array in javascript

Sep 27, 2011 No Comments by Mahdi Pedram

If you are trying to remove elements from an array. and do not care what those elements are, you shouldn’t use array slice, array splice.
however there is an easier way of doing this.
by just changin the length of an array we can modify our array and remove items from it.
 
var arr = [1,2,3,4,5];
arr.length = 2;
console.log( [...]

javascript Read more

Repeating a string without using a for loop in javascript

Sep 27, 2011 No Comments by Mahdi Pedram

Even though it is not recommended to use Array constructor. but sometimes we can get some usage of it.
One good example would be repeating a string without using a for loop.
in this example we are creating an empty array with default undefined values.
( when you specify a size for an array, without setting the values [...]

javascript Read more

Securing Undefined Variable In Javascript

Sep 26, 2011 No Comments by Mahdi Pedram

Sometimes some bad programmer or some hacker messes up with the undefined global variable in javascript.
so why would we really care about it.
the following are some examples that the variable undefined will be returned
 
 
var myVar = undefined; //Anything that has been set to the value of undefined.
 
function test(){}; console.log( test() ); // returns undefined – [...]

javascript Read more

Type Casting In Javascript

Sep 26, 2011 1 Comment by Mahdi Pedram

I see a lot of confusion among the javascript developers when it comes to casting in javascript.
Casting To A Number
let’s say you have a String and you want to convert it to a Number. one would say I will use parseInt() or parseFloat().
but there is even an easier way of doing it. no need to [...]

javascript Read more

Object Oriented with jQuery , javascript

Jan 20, 2011 No Comments

javascript is a scripting programming language that also supports Object Oriented Programming by its Prototypical Inheritance nature which is build in to the language.
most of the programmers in the world are used to Classical Object Oriented paradigm, and when they first start to do OO with javascript they will have a hard time.
Today what [...]

Read more

LRU Cache In Javascript

Jun 08, 2010 2 Comments

About two weeks ago, I was questioned about a LRU ( least recently used ) Cache in javascript , so I started doing some research on it and apparently I found a good idea to implement that . now the question is what is a LRU cache and why would we need it .
well basically [...]

Read more

Releasing jQuery Module Loader beta Version

May 14, 2010 No Comments

Its been 2 to 3 month , I was thinking about having a module loader in javascript .
so it will make my web applications more reliable and increase the readability of my code .
Now Let’s study one common scenario :
In large web development applications usually the backend Developer creates the Action File and [...]

Read more