objectively

1.0.0 • Public • Published

Objectively

A better OOP framework that follows better patterns:

  • No inheritance, use composition instead.
  • Objects are sealed, so no monkey patching.

About the package

  • I'm using semver.
  • I'm using the package actively.
  • The package has 48 test cases.

API

Environment Assumption

var objectively = require('objectively'),
    type = objectively.type,
    attr = objectively.attr,
    prop = objectively.prop

API list

type(constructor, ...methods)

Creates a objectively type, the object will frost and seal after calling this function.

  • constructor ^ Function : the constructor function.
  • [ methods ^ Array of Object ] : a list of properties added to the prototype. Methods defined here will override methods defined earlier.

Types get some toys too:

  • Constructor.is(object)

Checks if object is a instance of Constructor.

  • instance.chain

A function with the signature of function chain(f) { return f(this) } Not very useful on the first look, but believe me, it has a great power.

attr.reader(constructor, getter)

Adds a getter to constructor's prototype, should not be used after type.

  • constructor ^ Function: the constructor function.
  • getter ^ Function: the getter function.

attr.writer(constructor, setter)

Adds a setter to constructor's prototype, should not be used after type.

  • constructor ^ Function: the constructor function.
  • setter ^ Function: the setter function.

attr.accessor(constructor, getterAndSetter)

Adds a getter and setter to constructor's prototype, should not be used after type.

  • constructor ^ Function: the constructor function.
  • setter ^ Object: a object with a { get: Function, set: Function } format.

prop.reader(constructor, getter)

Adds a getter to the constructor, should not be used after type.

  • constructor ^ Function: the constructor function.
  • getter ^ Function: the getter function.

prop.writer(constructor, setter)

Adds a setter to the constructor, should not be used after type.

  • constructor ^ Function: the constructor function.
  • setter ^ Function: the setter function.

prop.accessor(constructor, getterAndSetter)

Adds a getter and setter to the constructor, should not be used after type.

  • constructor ^ Function: the constructor function.
  • setter ^ Object: a object with a { get: Function, set: Function } format.

Chaining

The way to make chainable functions is simple: just return this from the functions you want to chain.

To aid with the chaining every object has a .chain method on it.

License

Copyright (c) 2016 Christian Ferraz Lemos de Sousa

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

Readme

Keywords

Package Sidebar

Install

npm i objectively

Weekly Downloads

2

Version

1.0.0

License

MIT

Last publish

Collaborators

  • cferraz95