Git Product home page Git Product logo

simpleclassjs's Introduction

SimpleClassJS

This project is deprecated and no longer maintained. It is better to use ES6 Classes plus Babel instead.

Build Status

A lightweight JavaScript Class framework

Purpose

The purpose of this framework is to be lightweight (< 1K when minified) and clean, but offering full OO support, including subclassing, inheritance and so. There are better class JS frameworks out there, but this is an exercise to see if I can make something simple but powerful enough for a real app.

Download & Installation

  • Download Minified version available in dist folder
  • To include it in a web application:
    • Copy dist/Class.min.js where your javascripts are placed
    • Include it in your index.html as: <script type="text/javascript" src="PATH_TO_YOUR_JS/Class.min.js"></script>
  • To include it in a Node.js app:
    • Copy dist/Class.min.js where your javascripts are placed
    • Import it with var Class = require('PATH_TO_YOUR_JS/Class.min.js');

Usage

Create an empty class

var Empty = Class();
var instance = new Empty(); // Do nothing

Create a class with only a constructor

var Simple = Class({
    constructor: function() {
        alert("Hello World!");
    }
});
var instance = new Simple(); // alert "Hello world!"

Create a class with constructor, methods and context handling

var Car = Class({
    constructor: function(manufacturer, model) {
        this.manufacturer = manufacturer;
        this.model = model;
    },
    toString: function() {
        return this.manufacturer + " " + this.model;
    }
});
var honda = new Car("Honda", "Civic");
honda.toString(); // will return "Honda Civic" 

Basic inheritance with _super support to call parent methods

var HybridCar = Class(Car, {
    // Overrides Car.toString
    toString: function() {
        return this._super() + ' Hybrid';
    }
});

var hybrid = new HybridCar("Honda", "Civic");
hybrid.toString(); // will return "Honda Civic Hybrid"

Chained inheritance is also supported

var MyAwesomeCar = Class(HybridCar, {
    constructor: function(manufacturer, model, speed) {
        this._super(manufacturer, model);
        this.speed = speed;
    },
    getSpeed: function() {
        return this.speed;
    },
    toString: function() {
        return this._super() + ' is Awesome';
    }
});

simpleclassjs's People

Contributors

jalopez avatar

Stargazers

 avatar  avatar  avatar  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.