Fetching contributors…
Cannot retrieve contributors at this time
53 lines (41 sloc) 1.77 KB

Constants

< Methods | Main | Events >

Sources: components/meta/Constants.js

To define clazz constants use constants meta directive. To get constants use const() method of clazzes and clazz instances.

Example:

Online working version of this example is availabel on plunkr: http://plnkr.co/edit/kajA9m

clazz('SomeClazz', {
    constants: {
        PI: 3.14,
        NAME: 'Phil',
        COUNTRIES: {
            EURASIA: ['France', 'Germany', 'Russia', 'China'],
            AFRICA:  ['Egypt', 'Tunisia', 'Libya', 'South Africa'],
            NORTH_AMERICA: ['USA', 'Canada', 'Mexico'],
            SOUTH_AMERICA: ['Brasil', 'Argentina', 'Venezuela'],
            AUSTRALIA: ['Australia']
        }
    }
});

var SomeClazz = clazz('SomeClazz');
var someClazz = new SomeClazz();

document.write(
  'SomeClazz.const("PI"): '                  +SomeClazz.const('PI')+'<br>'+
  'SomeClazz.const("COUNTRIES","EURASIA"): ' +SomeClazz.const('COUNTRIES','EURASIA').join(', ')+'<br>'+
  'someClazz.const("NAME"): '                +someClazz.const('NAME')+'<br>'+
  'someClazz.const("COUNTRIES","AFRICA",0): '+someClazz.const("COUNTRIES","AFRICA",0)+'<br>' 
);

< Methods | Main | Events >

githalytics.com alpha