DelphiFAQ Home Search:
General :: Programming :: JavaScript
Code snippets to add functionality to your HTML pages, preferably cross-browser.

Articles:

This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.

Featured Article

Introducing namespaces into Javascript

Question:

How to avoid variable overlap problems (stepping on the fellow engineers' toes)

Answer:

Use namespaces as shown below. Make all functions members of an object - here named pt_scope - that is instantiated exactly one time. Then call functions as members of this global object.

<script language=javascript>
 function go() {
 
 var pt_scope = {
 	a: function() {alert('hello'); },
 	b: function() {document.write('junk'); }
   }
 
 
   pt_scope.a();
   pt_scope.b();
 }
 </script>
 <a href=javascript:go()>GO</a>
 

Generated 12:01:53 on Jan 21, 2018