
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.
class-wrapper
Advanced tools
Set of wrappers for easier definition of different kind of classes. Currently there are three kinds of wrappers:
ClassBuilder
- the main wrapper that realize the inheritance and data encapsulation. It requires a function that defines how the instances will be created. It returns the clone of defined instance builder function with special features and properties.Class
- it has predefined instance builder function for ClassBuilder
, that calls all parent's constructors before calling the constructor of a new classSingletonClass
- it has predefined instance builder function for ClassBuilder
, that by any new
always returns the same instance. The first instance will be created in the same way as Class
Each wrapper accepts:
Defined class properties are treated as default values for a new instance and they are isolated between instances. For example if some class has an object in properties then each instance will have its own copy of that default object. Only methods are shared.
If this library is planned to be used in some legacy environment then please add required plyfills. Here is a good resource: https://github.com/es-shims/es5-shim
Via NPM (Node Package Manager)
$ npm install class-wrapper --save
Available library files:
dest/class-wrapper.js
- not minified library packagedest/class-wrapper.min.js
- minified library packageThe destination library files are surrounded with the universal module definition. So it can be loaded
"class-wapper"
// Define a Figure class:
var Figure = Class(function() {
console.log('Figure::initialize()');
}, {
// abstract function for a calculating a suqare of a figure
calcArea: function() {}
});
// Define Rectangle class derived from a Figure class:
var Rectangle = Class(Figure, function(width, height) {
console.log('Rectangle::initialize()');
this._width = width;
this._height = height;
}, {
_width: 0,
_height: 0,
calcArea: function() {
return this._width * this._height;
}
});
// Define Square class as a special case of Rectangle:
var Square = Class(Rectangle, function(length) {
console.log('Square::initialize()');
this._height = length;
});
// Create a rectangle with width 2 and height 4
var someRect = new Rectangle(2, 4);
// the following lines will be logged in console:
// Figure::initialize()
// Rectangle::initialize()
console.log(someRect.calcArea()); // the area is: 8
// Create a square with an edge length 5
var someSqrt = new Square(5);
// the following lines will be logged in console:
// Figure::initialize()
// Rectangle::initialize()
// Square::initialize()
console.log(someSqrt.calcArea()); // the area is: 25
FAQs
Set of wrappers to define a class like in C++ and few utility functions
The npm package class-wrapper receives a total of 29 weekly downloads. As such, class-wrapper popularity was classified as not popular.
We found that class-wrapper 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.