The following links are the basic link provide the information how to create namspace and class in JavaScript.
- 3 ways to define a JavaScript class
- Javascript Namespace Declaration
- Private Static Members in Javascript
<!DOCTYPE html> <html> <head> <title>Test</title> <script type="text/javascript"> var NS = NS || {}; NS.Sound = function (name) { this.name = name; } NS.Sound.Variable = []; NS.Sound.Method1 = function () { NS.Sound.Variable.push(1); NS.Sound.Variable.push(2); NS.Sound.Variable.push(3); } NS.Sound.Method2 = function () { return NS.Sound.Variable.length; } function onLoad() { var sound = new NS.Sound("lovestory"); var div = document.getElementById("content"); NS.Sound.Method1(); var content = sound.name + " " + NS.Sound.Method2(); div.innerHTML = content; } document.addEventListener("DOMContentLoaded", onLoad, false); </script> </head> <body> <div id="content"></div> </body> </html>
No comments:
Post a Comment