Skip to content

Instantly share code, notes, and snippets.

@chubas
Created June 25, 2012 01:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chubas/2985860 to your computer and use it in GitHub Desktop.
Save chubas/2985860 to your computer and use it in GitHub Desktop.
Neon test
if(typeof require !== 'undefined') { // We are in Node, need to require the file
console.log("Requiring neon from file");
var Neon = require('../neon.js');
console.log(Neon);
// In Coffeescript, the following construct is recommended
// { Class, Module, Interface } = require('neon')
var Class = Neon.Class;
var Module = Neon.Module;
var Interface = Neon.Interface;
}
console.log('Class :', typeof Class);
console.log('Module :', typeof Module);
console.log('Interface :', typeof Interface);
Module('Composition')({
moduleClassVariable : 1,
prototype : {
moduleInstanceVariable : 2
}
});
Interface('Contract')({
constructor : ['ensuredClassVariable'],
prototype : ['ensuredInstanceVariable']
});
Class('BaseClass')({
baseClassVariable : 3,
prototype : {
baseInstanceVariable : 4
}
});
var AnonymousModule = Module()({
anonymousClassVariable : 5,
prototype : {
anonymousInstanceVariable : 6
}
});
Class('MyClass').inherits(BaseClass).ensures(Contract).includes(Composition, AnonymousModule)({
GREETING : 'HELLO',
inheritedClassVariable : 7,
ensuredClassVariable : 8,
prototype : {
inheritedInstanceVariable : 9,
ensuredInstanceVariable : 10,
init : function(argument) {
console.log(this.constructor.GREETING + ' ' + argument + '!');
}
}
});
var instance = new MyClass('world');
console.log(MyClass.moduleClassVariable);
console.log(instance.moduleInstanceVariable);
console.log(MyClass.baseClassVariable);
console.log(instance.baseInstanceVariable);
console.log(MyClass.anonymousClassVariable);
console.log(instance.anonymousInstanceVariable);
console.log(MyClass.inheritedClassVariable);
console.log(MyClass.ensuredClassVariable);
console.log(instance.inheritedInstanceVariable);
console.log(instance.ensuredInstanceVariable);
/// Output:
/*
Requiring neon from file
{ Class: [Function: Class],
Module: [Function: Module],
Interface: [Function: Interface] }
Class : function
Module : function
Interface : function
HELLO world!
undefined
2
3
4
undefined
6
7
8
9
10
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment