
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
classified-magic
Advanced tools
#Classified Magic
OOP for NodeJS with magic. Inspired by Classified
$ npm install classified-magic
var classified = require('classified-magic');
//root definition
var RootClass = classified(function() {
//sample constants
this.SOME_CONSTANT = 'foo';
//sample public properties
this.data = {};
this.sampleProperty = 4.5;
this.sampleDeepProperty = {
sample1: 'Hello',
sample2: [4, 5, 6, 7],
sample3: {
bool : true,
regex : /^abc/,
date : new Date(),
string : String
}
};
//sample protected properties
this._sampleProperty = 5.5;
this._sampleDeepProperty = {
sample1: '_Hello',
sample2: [8, 9, 0, 1]
};
//sample private properties
this.__sampleProperty = 6.5;
this.__sampleDeepProperty = {
sample1: '__Hello',
sample2: [12, 13, 14, 15]
};
//sample constructor
this.___construct = function() {
this.constructCalled = true;
};
//sample public method
this.sampleMethod = function() {
return this._sampleMethod();
};
//sample protected method
this._sampleMethod = function() {
return this.__sampleMethod();
};
//sample private method
this.__sampleMethod = function() {
return this.SOME_CONSTANT + this._sampleProperty;
};
this.sampleAccessMethod = function() {
return this.sampleMethod()
+ this._sampleMethod()
+ this.__sampleMethod();
};
//sample magic methods
this.___get = function(name) {
return this.data[name];
};
this.___set = function(name, value) {
this.data[name] = value;
};
this.___enum = function() {
return Object.keys(this.data);
};
this.___has = function(name, value) {
return this.data.hasOwnProperty(name);
};
this.___delete = function(name) {
delete this.data[name];
};
});
//sample child definition
//you can use object or function as the definition
var ChildClass = RootClass.extend(function() {
//sample constants
this.SOME_CONSTANT_2 = 'bar';
//sample protected properties
this._sampleProperty = 7.5;
//sample public methods
this.sampleMethod = function() {
return this._sampleMethod();
};
//sample protected methods
this._sampleMethod = function() {
return this.___parent._sampleMethod();
};
});
//instantiate child
var child = ChildClass.load();
//test it
console.log(child.sampleMethod()); //--> foo7.5
try {
child._sampleMethod();
} catch(e) {
console.log('Protected call did not work');
}
//test magic
child.foo = 4;
console.log(child.data.foo);
FAQs
OOP for NodeJS with magic
We found that classified-magic demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.