Javascript – Utilities

Posted: June 3, 2010 in Javascript
Tags:

Validation Checks – Reflection using typeof, hasOwnProperty

typeof Object.mymethod !== ‘function’ // check 2 see whether function exist or not before using it or defining a new one

myobject.hasOwnProperty(‘myvar’) // returns true if exist (parameter can be ‘mymethod’)

Javascript .replace() only replaces one instance of a character/string, use regular expression to replace all instances of char/string …

function replaceAll(txt, replace, with_this) {

return txt.replace(new RegExp(replace, ‘g’),with_this);

}

If you want to use .ReplaceAll() similar to javascript’s inbuilt .replace() function then use below lines of code …

String.prototype.ReplaceAll = function(find, replace){
var temp = this;
return temp.replace(new RegExp(find, ‘g’), replace));
}

escape Vs encodeURI Vs encodeURIComponent

http://xkr.us/articles/javascript/encode-compare/

JQuery has plug-in for this, but I should find some easy way for this …

Plug-in: http://plugins.jquery.com/project/escape

Creating time delays – setTimeout, setInterval, clearInterval

Check from http://www.howtocreate.co.uk/tutorials/javascript/timers for more details.

JQuery has .delay() from 1.4 release.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s