forked from fabiooshiro/namespace-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample2.html
45 lines (38 loc) · 1.35 KB
/
sample2.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<html>
<head>
<title>Sample namespace js</title>
<script type="text/javascript" src="namespace.js"></script>
<script type="text/javascript">
// file MyClass.js
namespace('sr.oshiro', {
'MyClass': function(){
this.myMethod = function(){
document.write('Hello word');
}
}
});
// You can add more class in the package or namespace with function
namespace('sr.oshiro', function(){
var privateVariable = 'nice';
function MyOtherClass(){
this.myMethod = function(){
alert(privateVariable);
}
}
function PrivateClass(){
this.myMethod = function() { alert('nothing') }
}
// export the public class
return {MyOtherClass: MyOtherClass};
});
// this is like "import br.oshiro.MyClass" for Java user
var MyClass = sr.oshiro.MyClass;
var myClass = new MyClass();
myClass.myMethod();
var myOtherClass = new sr.oshiro.MyOtherClass();
myOtherClass.myMethod();
</script>
</head>
<body>
</body>
</html>