Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

clazzy

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clazzy

A cross platform JavaScript library that provides a classical interface to prototypal inheritance.

  • 0.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Clazzy

A cross platform JavaScript library that provides a classical interface to prototypal inheritance.

Usage

Creating a class

var Foo = Clazzy.create(
{
	// Constructor
	// --------------------------------

	initialize : function ()
	{
		this.foo = 'foo';
	},

	// Instance methods
	// --------------------------------

	bar : function ()
	{
		return 'bar';
	},

	baz : function (baz)
	{
		return baz;
	},
	
	// Static methods
	// --------------------------------

	static : 
	{
		qux : function ()
		{
			return 'qux';
		}
	}
});

var foo = new Foo();

foo.foo; // 'foo'

foo.bar(); // 'bar'

foo.baz('baz'); // 'baz' 

Foo.qux(); // 'qux'

Note: Instance properties can be defined in the definition, however their inital value should be set in the constructor.

Creating a class that extends another class

var Bar = Clazzy.create(
{
	extend : Foo,

	// --------------------------------

	initialize : function ()
	{
		this.super();
	 // -------------

	 	this.corge = 'corge';
	},

	// --------------------------------

	baz : function ()
	{
		return 'bar';
	},

	baz : function (baz)
	{
		return 'super ' + this.super(baz);
	}
});

var bar = new Bar();

bar.foo; // 'foo'

bar.corge; // 'corge'

bar.bar(); // 'bar'

bar.baz('qux'); // 'super qux'

Bar.qux(); // throws an error

Note:

  • Static methods are not inherited.
  • If a method overrides one of its base class methods, you can invoke the overridden method through the use of the super method.

Creating a class that includes another class

Clazzy provides a method of code reuse called includes. Behaving similarly to Ruby's mixins and PHP's traits, they enable a developer to reuse sets of methods freely in several independent classes living in different class hierarchies.

var Baz = Clazzy.create(
{
	include : [Foo],

	// --------------------------------

	moo : function ()
	{
		return 'moo';
	}
});

var baz = new Baz();

baz.foo; // 'foo'

baz.bar(); // 'bar'

baz.baz('baz'); // 'baz'

baz.moo(); // 'moo'

Baz.qux(); // throws an error

Note:

  • Static methods are not included.
  • The super method, when invoked from an included method, does not reference the hierarchy of the class it's included in.
  • The precedence order is that an inherited member from a base class is overridden by an included member, which in turn are both overridden by a member from the current class.

Getting started

Node

Clazzy is available through the Node Package Manager, so you can install like so:

npm install clazzy

and bring into your code like so:

var Clazzy = require('clazzy');

Browser

To use Clazzy in a browser envrionment, just use a script tag like so:

<script type="text/javascript" src="path/to/Clazzy.js"></script>

To remove Clazzy from the global namespace, you can use Clazzy.noConflict(), like so:

Namespace.Clazzy = Clazzy.noConflict();

Development

Grunt is used to handle the build process for Clazzy. To perform a full build, use the build task:

grunt build

which is just an alias for the default task:

grunt

To only check code quality and/or run unit tests use the test task:

grunt test

License

Clazzy is released under the MIT License.

Keywords

FAQs

Package last updated on 14 Sep 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc