Skip to main content

Posts

Showing posts with the label javascript

Javascript notes

What is the difference between call and apply? The difference is that  apply  lets you invoke the function with arguments as an array;  call requires the parameters be listed explicitly. A useful mnemonic is "A for array and C for comma." See MDN's documentation on  apply  and  call . Pseudo syntax: theFunction.apply(valueForThis, arrayOfArgs) theFunction.call(valueForThis, arg1, arg2, ...) Sample code: function theFunction ( name , profession ) { alert ( "My name is " + name + " and I am a " + profession + "." ); } theFunction ( "John" , "fireman" ); theFunction . apply ( undefined , [ "Susan" , "school teacher" ]); theFunction . call ( undefined , "Claude" , "mathematician" ); Map vs Object in JavaScript According to mozilla: A Map object can iterate its elements in insertion order - a for..of loop will return an array of [key, v...

Redirection in javascript

How Page Re-direction works ? Example 1: This is very simple to do a page redirect using JavaScript at client side. To redirect your site visitors to a new page, you just need to add a line in your head section as follows: <head> <script type="text/javascript"> <!-- window.location="http://www.newlocation.com"; --> </script> </head> To understand it in better way you can  Try it yourself . Example 2: You can show an appropriate message to your site visitors before redirecting them to a new page. This would need a bit time delay to load a new page. Following is the simple example to implement the same: <head> <script type="text/javascript"> <!-- function Redirect() { window.location="http://www.newlocation.com"; } document.write("You will be redirected to main page in 10 sec."); setTimeout('Redirect()', 10000); //--> </script> </head> Here  ...