-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME
86 lines (65 loc) · 1.76 KB
/
README
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/**
example/simple.js
declare is a node.js optimized version of dojo 1.7's dojo.declare
This example shows how to create a namespace and create classes within.
No global namespace is violated
declare includes the folloing modified dojo functions
* declare
* mixin
* getObject
* setObject
* exists
* getProp
for more information check the dojo docs (with dojo. prefix for sure)
**/
var createNamespace = require("../index");
var myCustomNamespace = {
"doesNotMatter" : "anyValue"
};
var oop = createNamespace(myCustomNamespace);
var MYClass = oop.declare("my.namespace.MYCLASS",[],{
property:"value",
constructor:function(){
console.log("I AM ALIVE");
},
methodA:function(){
console.log("methodA called")
console.log(this);
},
methodB:function(){
console.log("methodB called")
}
});
oop.declare("MYSubClass",[myCustomNamespace.my.namespace.MYCLASS],{
constructor:function(){
oop.mixin(this,{methodC:function(){
console.log("same mixin like known from dojo @" , this.declaredClass);
}});
},
methodA:function(){
console.log("method A from " + this.declaredClass);
}
})
/*
this will end up with the same result...
*/
var instance = new MYClass();
/*
The namespace can be accessed with the object we used to create the "oop" instance.
You could create more factories each with a different namespace
*/
var i2 = new myCustomNamespace.my.namespace.MYCLASS();
var subi = new myCustomNamespace.MYSubClass();
subi.methodA();
subi.methodB();
subi.methodC();
/**
this will print nonsense but working output:
===========================================
I AM ALIVE
I AM ALIVE
I AM ALIVE
method A from MYSubClass
methodB called
same mixin like known from dojo @ MYSubClass
**/