# classified-magic

> OOP for NodeJS with magic

Latest version **0.1.5** (published 2014-10-08) · 0 weekly downloads

## Install

```sh
npm install classified-magic
pnpm add classified-magic
yarn add classified-magic
bun add classified-magic
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.5 |
| Published | 2014-10-08 |
| First published | 2014-09-08 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Christian Blanquera |
| Maintainers | cblanquera |
| Keywords | oop, class, protected, parent, structure, constructor, inheritence, constant, magic |

## Links

- npm: https://www.npmjs.com/package/classified-magic
- Repository: https://github.com/cblanquera/magic
- Issues: https://github.com/cblanquera/magic/issues
- npm.io page: https://npm.io/package/classified-magic

## Dependencies (1)

- [classified](https://npm.io/package/classified.md) 0.1.3

## Recent versions

- 0.1.5 (latest) — 2014-10-08
- 0.1.4 — 2014-10-02
- 0.1.3 — 2014-10-02
- 0.1.2 — 2014-10-01
- 0.1.1 — 2014-09-17
- 0.0.14 — 2014-09-17
- 0.0.13 — 2014-09-12
- 0.0.12 — 2014-09-11
- 0.0.10 — 2014-09-10
- 0.0.9 — 2014-09-10
- 0.0.8 — 2014-09-10
- 0.0.6 — 2014-09-09
- 0.0.5 — 2014-09-09
- 0.0.3 — 2014-09-09
- 0.0.2 — 2014-09-08
- … 1 more at https://npm.io/package/classified-magic/versions

## README

#Classified Magic

  OOP for NodeJS with magic. Inspired by [Classified](https://github.com/cblanquera/classified)

[![Build Status](https://api.travis-ci.org/cblanquera/classified-magic.png)](https://travis-ci.org/cblanquera/classified-magic/)

[![NPM](https://badge.fury.io/js/classified-magic.svg)](https://www.npmjs.org/package/classified-magic)

### Installation

```bash
$ npm install classified-magic
```

## Quick Start

```
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);
```

### Features

  * Public, Private, Protected
  * Constants
  * Inheritance
  * Works on server or client
  * Magic methods - get, set and iterators

### Methods

  * define(object|function) - Defines the class
  * extend(object|function) - Adds a parent to be combined with the definition
  * definition() - Returns the entire definition including the protected and private properties
  * parents() - Returns direct parents of this definition
  * get() - Returns the publically accessable class definition function
  * load() - Returns class defined instantiation
  * register(string) - saves a state of the definition which can be recalled in trait
  * trait(string|function|object) - will setup the provided as a parent, if string will recall from registry

### What's up with the underscores?

  * _ - protected properties and methods
  * __ - private properties and methods
  * ___ - Magic placeholder

---
_Source: https://npm.io/package/classified-magic · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
