Code Monkey home page Code Monkey logo

jsclass's Introduction

@description Class

A class based OO inheritance pattern implementation in Javascript. Exports a module which works in AMD, NodeJS and CommonJS

Useage

Pass an object in with the functions you want all instances of the class to start with. Modify the class variable to add functions.

Define a class (type):

  var Vehicle = Objects.Class({});

Instanciation:

var v = new Vehicle();

Define a class with a constructor:

var Vehicle = Objects.Class({
	init: function(manufacturer) {
		this.manufacturer = manufacturer;
	}
});

Instanciate a class with a constructor:

var v = new Vehicle('Big Cars Incorporated');

Define a subclass:

var Car = Objects.Class(Vehicle, {});

Define a subclass with a constructor

__super can be positioned anywhere in the arguments list.

var Car = Objects.Class(Vehicle, {
	init: function(manufacturer, model) {
		this.model = model;
	}
});

Define a subclass with a constructor, calling the overridden function

__super here is a reference to the Vehicle.init() function. It can appear anywhere in the arguments list.

Change '__super' to be a different variable name in modules.settings.superclassInjector

  var Car = Objects.Class(Vehicle, {
	  init: function(__super, manufacturer, model) {
		  this.model = model;

		  // call the superclass constructor, passing in the parameter.
		  __super.init(manufacturer);
	  }
  });

Inheritance + mixins:

  var Trailer = Objects.Class(Vehicle, Car, {});

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.