Coder Social home page Coder Social logo

in_js's Introduction

In.js : prototypal inheritance done right

In comes from Inheritance because this is what the lib addresses. More accurately, it simplifies prototypal inheritance. In.js is under MIT license.

It is minimal by design and it takes care of some details often overlooked:

  • the constructor of an instance of T points to the function T, as expected
function Base() {}
Base.prototype.K = 0;

//Bad free style
function Sub() {}
Sub.prototype = new Base();
var s = new Sub();
s.K === 0; //true
s.constructor === Sub; //false

//With In.js
function Sub2() {}
In.inheritFrom(Sub2, Base);
s.K === 0; //true
s.constructor === Sub2; //true
  • it provides a zuper member with which to access the parent class and constructor
function Base(x) { this.x = x; }
function Sub(x) { this.zuper(x); }
In.inheritFrom(Sub, Base);
var s = new Sub(2);
s.x === 2; //true
  • the In.inheritFrom(...) method can be called at any point of the class definition. Just after the Ctor definition, after the last member definition or at any point in between.
function Base() {}
function Sub() {}
Sub.prototype.Y = 1; //not overwritten by the following call
In.inheritFrom(Sub, Base);
Sub.prototype.Z = 2; //not ignored when done after inheriting

var s = new Sub();
s.Y === 1; //true
s.Z === 2; //true
  • ... and it performs checks like avoiding the repeated inheritance of the same class

Docs and examples

Documentation is available here.

The spec file contains some examples of use. A coverage report is available too.

How do I get set up?

  • How to use the lib (basic)
    • copy js/src/In.js in your project
    • add it to your HTML in a script tag. The module will be attached to window.In
  • How to use the lib (advanced)
    • The lib is a Bower component. You can add it to your dependencies in this way:
    "dependencies": {
        "in_js": "git+https://github.com/valentinomiazzo/in_js.git"
    }
    • The lib is a Require.js module. Remember to add it to your require.config()
  • How to modify the lib, run tests, etc...
    • Prerequisites
      • install Node.js
      • install Npm
      • npm install grunt-cli -g
      • npm install bower -g
    • Install
      • clone this repository
      • in the root of the cloned repo, type (on Windows you may need to disable antivirus if you get strange issues during the install):
      • npm install
      • On some platforms you may need to install apt-get install nodejs-legacy if the command above doesn't work.
    • Build
      • grunt
      • docs are generated in build/docs
    • Test
      • Jasmine it is used for testing.
      • tests are in js/spec
      • tests reports are in build/tests
      • coverage reports are in build/coverage

Contribution guidelines

  • For pull requests
  • For issues

in_js's People

Contributors

valentinomiazzo avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.