This repository has been archived by the owner on Dec 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjfork-2.0.js
815 lines (678 loc) · 22.9 KB
/
jfork-2.0.js
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
/*!
* jfork JavaScript Framework v2.0
* http://jfork.com/
*
* Copyright 2013 The Jeffries Company and other contributors
* Released under the MIT license
* https://github.com/JeffriesCo/JFork/blob/master/LICENSE
*/
(function(window, undefined) {
//Check if supported
if(!Object.defineProperty){
throw new Error("jfork is not supported");
return;
}
//Setup jfork base object - default functionality is to use jfork.Class
var jfork = function(){
return jfork.Class.apply(null,Array.prototype.slice.call(arguments));
};
//Save a copy of jfork before replacing it
var _jfork = window.jfork;
window.jfork = jfork;
//Public noConflict
jfork.noConflict = function(){
window.jfork = _jfork;
return jfork;
};
//Public onError
jfork.onError = function(msg){
throw new Error(msg);
};
var typeChecks = {};
jfork.is = function(o){
for(var t in typeChecks){
if(t != "Variant" && typeChecks[t](o)){
return t;
}
}
return null;
};
jfork.addTypeCheck = function(name,check){
name = name.charAt(0).toUpperCase() + name.slice(1);
typeChecks[name] = check;
jfork.is[name] = check;
};
jfork.hasTypeCheck = function(name){
if(name in typeChecks){
return true;
}
return false;
};
//Add Default Types
jfork.addTypeCheck("Number",function(o){
return ((o || o==0) && !isNaN(o) && o.constructor == Number) ? true : false;
});
jfork.addTypeCheck("Function",function(o){
return (o instanceof Function) ? true : false;
});
jfork.addTypeCheck("NodeList",function(o){
return (o && typeChecks["Number"](o.length) && typeChecks["Function"](o.item)) ? true : false;
});
jfork.addTypeCheck("Date",function(o){
return (o instanceof Date) ? true : false;
});
jfork.addTypeCheck("Element",function(o){
return o && ((HTMLElement && o instanceof HTMLElement) || "undefined" !== typeof o.childNodes || o.nodeType) ? true : false;
});
jfork.addTypeCheck("Array",function(o){
return (o && o.constructor == Array) ? true : false;
});
jfork.addTypeCheck("Object",function(o){
return (o && typeof o=="object" && !typeChecks["Array"](o) && !typeChecks["Element"](o) && !typeChecks["Date"](o) && !typeChecks["NodeList"](o) && !typeChecks["RegExp"](o)) ? true : false;
});
jfork.addTypeCheck("String",function(o){
return (typeof o == 'string') ? true : false;
});
jfork.addTypeCheck("Boolean",function(o){
return (typeof o == "boolean") ? true : false;
});
jfork.addTypeCheck("RegExp",function(o){
return (o && o instanceof RegExp) ? true : false;
});
jfork.addTypeCheck("Integer",function(o){
return (typeChecks["Number"](o) && ((o + "").indexOf(".")==-1)) ? true : false;
});
jfork.addTypeCheck("Variant",function(o){
return true;
});
//Internal Helpers
var bind = function(func,context){
return function(){
return func.apply(context,Array.prototype.slice.call(arguments));
};
};
var observe = function(obj,name,_getter,_setter){
var value = obj[name];
var getter = function() {
return _getter.call(obj, value);
};
var setter = function(newValue) {
value = _setter.call(obj, newValue);
return value;
};
Object.defineProperty(obj, name, {get:getter, set:setter, configurable:true});
};
var foreach = function(o,func){
if(!o){
return;
} else if(o.constructor == Array){
for(var i=0, len=o.length; i<len; i++){
var val = func(i,o[i],o);
if(val !== undefined){
return val;
}
}
} else {
for(var i in o){
var val = func(i,o[i],o);
if(val !== undefined){
return val;
}
}
}
return;
};
//JFork Class and Base
jfork.Class = function(defaultSignature,extend){
//Storage Structure
var clazz = {
privateStatic:null,
publicStatic:null,
signature:{
constructors:[],//[{isPrivate:bool,value:function(){},isParamObject:bool,params:[{name:"asdf",type:"Variant|null",isArray:bool},...]},...]
variables:{}, //{name:{type:"Variant|null",isPrivate:bool,isStatic:bool,value:value},...}
methods:{} //{name:{value:function(){},variations:[{type:"Variant|null",isPrivate:bool,isStatic:bool,value:function(){},isParamObject:bool,params:[{name:"asdf",type:"Variant|null",isArray:bool},...]},...]},...}
},
staticMapping:{
variables:{}, //{name:storageObject,...}
methods:{} //{name:context,...}
},
storage:{}, //{name:value,...}
instances:[],
extend:extend || null
};
//Bind Method
var bindMethod = function(signature,applyTo,contexts){
var func = bind(signature.value,applyTo);
foreach(contexts,function(i,v){
v[signature.variations[0].name] = func;
});
};
//Bind Variable
var bindVariable = function(signature,storage,contexts){
var getter = function(){
return storage[signature.name];
};
var setter = function(newValue){
storage[signature.name] = newValue;
};
if(signature.type){
setter = function(newValue){
if(signature.isTypeArray){
if(!jfork.is.Array(newValue)){
jfork.onError(signature.name + ": is the wrong type. Expected a " + signature.type + "[]");
}
for(var i=0; i<newValue.length; i++){
if(!jfork.is[signature.type](newValue[i])){
jfork.onError(signature.name + ": is the wrong type. Expected a " + signature.type + "[]");
}
}
} else {
if(!jfork.is[signature.type](newValue)){
jfork.onError(signature.name + ": is the wrong type. Expected a " + signature.type);
}
}
storage[signature.name] = newValue;
};
}
foreach(contexts,function(i,v){
observe(v,signature.name,getter,setter);
});
};
//Check Parameters
var checkParams = function(parameters,signature){
if(signature.params == null){
return true;
} else if(signature.isParamObject){
if(parameters.length != 1){
return false;
} else if(!jfork.is.Object(parameters[0])){
return false;
} else {
for(var i=0; i<signature.params.length; i++){
if(signature.params[i].name in parameters[0]){
if(signature.params[i].type){
if(signature.params[i].isArray){
if(jfork.is.Array(parameters[0][signature.params[i].name])){
for(var j=0; j<parameters[0][signature.params[i].name].length; j++){
if(!jfork.is[signature.params[i].type](parameters[0][signature.params[i].name][j])){
return false;
}
}
} else {
return false;
}
} else if(!jfork.is[signature.params[i].type](parameters[0][signature.params[i].name])) {
return false;
}
}
} else {
return false;
}
}
}
} else {
if(parameters.length != signature.params.length){
return false;
} else {
for(var i=0; i<parameters.length; i++){
if(signature.params[i].type){
if(signature.params[i].isArray){
if(jfork.is.Array(parameters[i])){
for(var j=0; j<parameters[i].length; j++){
if(!jfork.is[signature.params[i].type](parameters[i][j])){
return false;
}
}
} else {
return false;
}
} else if(!jfork.is[signature.params[i].type](parameters[i])) {
return false;
}
}
}
}
}
return true;
};
//Build Method
var buildMethod = function(variations){
//Single Method
if(variations.length == 1){
var funcA = variations[0].value;
if(variations[0].params){
funcA = function(){
var args = Array.prototype.slice.call(arguments);
if(!checkParams(args,variations[0])){
jfork.onError(variations[0].name + ": parameters passed do not match method signature");
}
return variations[0].value.apply(this,args);
};
}
if(variations[0].isVoid){
return function(){
var rtnval = funcA.apply(this,Array.prototype.slice.call(arguments));
if(rtnval !== undefined){
jfork.onError(variations[0].name + ": is defined as void and cannot return a value.");
}
};
} else if(variations[0].type){
return function(){
var rtnval = funcA.apply(this,Array.prototype.slice.call(arguments));
if(variations[0].isTypeArray){
if(!jfork.is.Array(rtnval)){
jfork.onError(variations[0].name + ": must return type " + variations[0].type + "[]");
}
for(var i=0; i<rtnval.length; i++){
if(!jfork.is[variations[0].type](rtnval[i])){
jfork.onError(variations[0].name + ": must return type " + variations[0].type + "[]");
}
}
} else if(!jfork.is[variations[0].type](rtnval)){
jfork.onError(variations[0].name + ": must return type " + variations[0].type);
}
return rtnval;
};
} else {
return funcA;
}
//Overloaded Method
} else {
return function(){
var args = Array.prototype.slice.call(arguments);
var validvariationsIndex = foreach(variations,function(i,v){
if(checkParams(args,v)){
return i;
}
});
if(!validvariationsIndex===undefined){
jfork.onError(variations[validvariationsIndex].name + ": parameters passed do not match method signature");
}
var rtnval = variations[validvariationsIndex].value.apply(this,args);
if(variations[validvariationsIndex].isVoid){
if(rtnval !== undefined){
jfork.onError(variations[validvariationsIndex].name + ": is defined as void and cannot return a value.");
}
} else if(variations[validvariationsIndex].type){
if(variations[validvariationsIndex].isTypeArray){
if(!jfork.is.Array(rtnval)){
jfork.onError(variations[validvariationsIndex].name + ": must return type " + variations[validvariationsIndex].type + "[]");
}
for(var i=0; i<rtnval.length; i++){
if(!jfork.is[variations[validvariationsIndex].type](rtnval[i])){
jfork.onError(variations[validvariationsIndex].name + ": must return type " + variations[validvariationsIndex].type + "[]");
}
}
} else if(!jfork.is[variations[validvariationsIndex].type](rtnval)){
jfork.onError(variations[validvariationsIndex].name + ": must return type " + variations[validvariationsIndex].type);
}
}
return rtnval;
};
}
};
//Build Signature
var buildSignature = function(def,value){
var defParts = def.split("(");
var defLeftParts = defParts[0].split(" ");
var sig = {
name:defLeftParts[defLeftParts.length-1],
type:null,
isTypeArray:false,
isParamObject:false,
params:null,
isPrivate:(def.indexOf("private ") > -1) ? true : false,
isStatic:(def.indexOf("static ") > -1) ? true : false,
isVoid:(def.indexOf("void ") > -1) ? true : false,
value:value
};
if(defLeftParts.length > 1){
var possibleType = defLeftParts[defLeftParts.length-2];
var isTypeArray = false;
if(possibleType.indexOf("[]") > -1){
isTypeArray = true;
possibleType = possibleType.replace("[]","");
}
if(jfork.hasTypeCheck(possibleType)){
sig.isTypeArray = isTypeArray;
sig.type = possibleType;
if(sig.isVoid){
jfork.onError(sig.name + ": cannot be both void and return a data type");
}
}
}
if(defParts.length == 2){
sig.params = [];
var paramsString = defParts[1].split(")")[0];
sig.isParamObject = paramsString.indexOf("{") > -1 ? true : false;
paramsString = paramsString.replace("{","").replace("}","");
var paramsSplit = paramsString.split(",");
if(paramsSplit.length > 1 || (paramsSplit.length==1 && paramsSplit[0] !="")){
foreach(paramsSplit,function(i,v){
v = v.replace(/^\s+|\s+$/g, '');
var paramSplit = v.split(" ");
var param = {name:paramSplit[paramSplit.length-1],type:"Variant",isArray:false};
if(paramSplit.length==2){
if(paramSplit[0].indexOf("[]") > -1){
param.isArray = true;
paramSplit[0] = paramSplit[0].replace("[]","");
}
if(jfork.hasTypeCheck(paramSplit[0])) {
param.type = paramSplit[0];
}
}
sig.params.push(param);
});
//Check for duplicate parameter names
var paramDuplicates = {};
foreach(sig.params,function(i,v){
if(paramDuplicates[v.name]){
jfork.onError(sig.name + ": cannot have two parameters with the same name (" + v.name + ")");
}
paramDuplicates[v.name] = true;
});
}
}
return sig;
};
//Are Params Equal
var areParamsEqual = function(sig1,sig2){
if(!sig1.params || !sig2.params){
return true;
} else if(sig1.params.length == sig2.params.length && sig1.isParamObject == sig2.isParamObject) {
for(var i=0; i<sig1.params.length; i++){
if(sig1.params[i].type != sig2.params[i].type && sig1.params[i].type != null && sig1.params[i].type != "Variant" && sig2.params[i].type != null && sig2.params[i].type != "Variant"){
return false;
}
}
return true;
} else if(sig1.isArgsObject && sig2.params.length == 1 && (sig2.params[0].type == null || sig2.params[0].type == "Variant" || sig2.params[0].type == "Object")) {
return true;
} else if(sig2.isArgsObject && sig1.params.length == 1 && (sig1.params[0].type == null || sig1.params[0].type == "Variant" || sig1.params[0].type == "Object")) {
return true;
}
return false;
};
//Creates a new Instance
var newClass = function(){
if(this instanceof newClass){ return; } //Used to prevent recursion from prototype on publicStatic
var args = Array.prototype.slice.call(arguments);
var instance = {
publicDynamic: new clazz.publicStatic(),
privateDynamic: bind(newClass),
dynamicMapping:{
variables:{}, //{name:storageObject,...}
methods:{} //{name:context,...}
},
storage:{} //{name:value,...}
};
clazz.instances.push(instance);
//Extra methods defined after the instance has been created - want to keep separate from default signature
var definedMethodVariations = {}; //{name:variationsArray}
//Instance Define
instance.publicDynamic.define = function(a,b){
if(jfork.is.Object(a)){
foreach(a,function(i,v){
instance.publicDynamic.define(i,v);
});
return instance.publicDynamic;
}
var signature = buildSignature(a,b);
//Variable
if(!jfork.is.Function(signature.value)){
instance.storage[signature.name] = signature.value;
var contexts = [instance.privateDynamic];
if(!signature.isPrivate){
contexts.push(instance.publicDynamic);
}
//Doesn't matter if static - because it only applies to this instance
bindVariable(signature,instance.storage,contexts);
//Constructor
} else if(signature.name == "construct") {
//Ignore - can be set on Classes only
//Method
} else {
var variations = [];
if(clazz.signature.methods[signature.name]){
variations = variations.concat(clazz.signature.methods[signature.name].variations);
}
if(definedMethodVariations[signature.name]){
variations = variations.concat(definedMethodVariations[signature.name]);
} else {
definedMethodVariations[signature.name] = [];
}
if(variations.length > 1){
var isDuplicate = foreach(variations,function(i,v){
if(areParamsEqual(signature,v)){
return true;
}
});
if(isDuplicate){
jfork.onError(signature.name + ": Cannot create two methods with the same signatures.");
}
}
definedMethodVariations[signature.name].push(signature);
var value = buildMethod(variations.concat([signature]));
var contexts = [instance.privateDynamic];
if(!signature.isPrivate){
contexts.push(instance.publicDynamic);
}
//Doesn't matter if static - because it only applies to this instance
bindMethod({value:value,variations:definedMethodVariations[signature.name]},instance.privateDynamic,contexts);
}
return instance.publicDynamic;
};//End define
//Run extended constructor and bind its methods and variables
if(clazz.extend){
instance.publicDynamic._super = instance.privateDynamic._super = clazz.extend.publicStatic.apply(null,args);
var applyExtend = function(curExtend){
if(!curExtend){
return;
} else if(curExtend.extend){
applyExtend(curExtend.extend);
}
foreach(curExtend.signature.methods,function(i,v){
if(!clazz.signature.methods[i]){
var contexts = [instance.privateDynamic];
if(!v.isPrivate){
contexts.push(instance.publicDynamic);
}
var applyTo = curExtend.staticMapping.methods[i];
if(!v.isStatic){
applyTo = curExtend.instances[curExtend.instances.length-1].dynamicMapping.methods[i];
}
bindMethod(v,applyTo,contexts);
}
});
foreach(curExtend.signature.variables,function(i,v){
if(!clazz.signature.variables[i]){
var contexts = [instance.privateDynamic];
if(!v.isPrivate){
contexts.push(instance.publicDynamic);
}
var applyTo = curExtend.staticMapping.variables[i];
if(!v.isStatic){
applyTo = curExtend.instances[curExtend.instances.length-1].dynamicMapping.variables[i];
}
bindVariable(v,applyTo,contexts);
}
});
};
applyExtend(clazz.extend);
}
//Bind Variables and Methods to Instance
foreach(clazz.signature.methods,function(i,v){
var contexts = [instance.privateDynamic];
if(!v.variations[0].isPrivate){
contexts.push(instance.publicDynamic);
}
var bindTo = clazz.staticMapping.methods[i];
if(!v.variations[0].isStatic){
instance.dynamicMapping.methods[i] = instance.privateDynamic;
bindTo = instance.dynamicMapping.methods[i];
}
bindMethod(v,bindTo,contexts);
});
foreach(clazz.signature.variables,function(i,v){
var contexts = [instance.privateDynamic];
if(!v.isPrivate){
contexts.push(instance.publicDynamic);
}
var storage = clazz.staticMapping.variables[i];
if(!v.isStatic){
instance.dynamicMapping.variables[i] = instance.storage;
instance.storage[i] = v.value;
storage = instance.dynamicMapping.variables[i];
}
bindVariable(v,storage,contexts);
});
//Run Local Constructor
var constructorFound = foreach(clazz.signature.constructors,function(i,v){
if(checkParams(args,v)){
v.value.apply(instance.privateDynamic,args);
return true;
}
});
if(!constructorFound && (clazz.signature.constructors.length > 0 || (clazz.signature.constructors.length == 0 && args.length > 0))){
jfork.onError("No constructor found matching these parameters.");
}
return instance.publicDynamic;
};//End newClass
//Setup Static Contexts
clazz.publicStatic = newClass;
clazz.privateStatic = bind(newClass);
//Add prototypes for instanceof
clazz.publicStatic.prototype = extend ? new extend.publicStatic() : {};
clazz.publicStatic.prototype.constructor = clazz.publicStatic;
//Defines static and stores dynamic to defaultSignature - from static methods and Class
clazz.publicStatic.define = function(a,b){
if(jfork.is.Object(a)){
foreach(a,function(i,v){
clazz.publicStatic.define(i,v);
});
return clazz.publicStatic;
}
var signature = buildSignature(a,b);
//Variable
if(!jfork.is.Function(signature.value)){
clazz.signature.variables[signature.name] = signature;
if(signature.isStatic){
clazz.storage[signature.name] = signature.value;
clazz.staticMapping.variables[signature.name] = clazz.storage;
var contexts = [clazz.privateStatic];
if(!signature.isPrivate){
contexts.push(clazz.publicStatic);
}
bindVariable(signature,clazz.storage,contexts);
}
//Constructor
} else if(signature.name == "construct") {
var isDuplicate = foreach(clazz.signature.constructors,function(i,v){
if(areParamsEqual(signature,v)){
return true;
}
});
if(isDuplicate){
jfork.onError("Cannot create two constructors with the same parameters.");
}
clazz.signature.constructors.push(signature);
//Method
} else {
if(!clazz.signature.methods[signature.name]){
clazz.signature.methods[signature.name] = {value:function(){},variations:[]};
} else {
var isDuplicate = foreach(clazz.signature.methods[signature.name].variations,function(i,v){
if(areParamsEqual(signature,v)){
return true;
}
});
if(isDuplicate){
jfork.onError(signature.name + ": Cannot create two methods with the same signatures.");
}
}
clazz.signature.methods[signature.name].variations.push(signature);
clazz.signature.methods[signature.name].value = buildMethod(clazz.signature.methods[signature.name].variations);
if(signature.isStatic){
clazz.staticMapping.methods[signature.name] = clazz.privateStatic;
var contexts = [clazz.privateStatic];
if(!signature.isPrivate){
contexts.push(clazz.publicStatic);
}
bindMethod(clazz.signature.methods[signature.name],clazz.privateStatic,contexts);
}
}
return clazz.publicStatic;
};
//Extend - extends the current class to create a new one
clazz.publicStatic.extend = function(extendClassSignature){
return jfork.Class(extendClassSignature,clazz);
};
//Setup default Class Signature
clazz.publicStatic.define(defaultSignature);
//Setup extended Class Signature
var applyStaticExtend = function(curExtend){
if(!curExtend){
return;
} else if(curExtend.extend){
applyStaticExtend(curExtend.extend);
}
foreach(curExtend.signature.methods,function(i,v){
if(v.variations[0].isStatic && !clazz.signature.methods[i]){
clazz.staticMapping.methods[i] = curExtend.staticMapping.methods[i];
var contexts = [clazz.privateStatic];
if(!v.isPrivate){
contexts.push(clazz.publicStatic);
}
bindMethod(v,clazz.staticMapping.methods[i],contexts);
}
});
foreach(curExtend.signature.variables,function(i,v){
if(v.isStatic && !clazz.signature.variables[i]){
clazz.staticMapping.variables[i] = curExtend.staticMapping.variables[i];
var contexts = [clazz.privateStatic];
if(!v.isPrivate){
contexts.push(clazz.publicStatic);
}
bindVariable(v,clazz.staticMapping.variables[i],contexts);
}
});
};
applyStaticExtend(clazz.extend);
return clazz.publicStatic;
};
//Helpers - each, bind, addTypeCheck, load,
//Classes - AJAX, API, DAO, Group, Widget, Timer, Data (prettyTime), Color, Animation, Canvas, Image, Sound
})(window);
/*
*
DOCUMENTATION
- Show argument types
- Common Patterns using JFork
- Talk about speed - http://jsperf.com/getter-setter/8
- First come first served on similar type checks
JFork
JFork Library
Must Haves
- No Conflict
- jfork.type
- jfork.Class
- Constructor
- private, public
- static, dynamic
- variables, functions
- need to deep clone on objects and arrays.. being set as variables
- instanceOf
- extends
- super???
- singletons - be able to do these!
- be able to get a reference internally to the new class.... normally this()
- type checking returns and arguments (should we use getters and setters?)
- overloaded methods and constructor - useful for multi purpose funcitons - i.e. method("hello",function(){}) vs. method({hello:"hello",onComplete:function(){}})
- check number of arguments first, then types
- have to wrapper in function of same name, that then contains an array of possibilities
- We don't want too many wrapper functions...
- arguments come in always as an object - (kinda restricting...)
- Need to be able to instantiate and extend immediately - examples needed...
- Annotations...? getters and setters, deprecate
*/