Javascript – Utilities

Posted: June 3, 2010 in Javascript

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

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


Creating time delays – setTimeout, setInterval, clearInterval

Check from for more details.

JQuery has .delay() from 1.4 release.


Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s