New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

chic

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chic

Chic is an extremely simple class-like interface to JavaScript prototypal inheritance

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
16
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

Chic

Chic is an extremely simple class-like interface to JavaScript prototypal inheritance.

Current Version: 0.0.1
Automated Build Status: Build Status

Getting Started

You can use Chic in-browser or on the server side with Node.js. On the client side, you can either install Chic through Component:

$ component install rowanmanning/chic

Or by simply including chic.js in your page:

<script src="path/to/lib/chic.js"></script>

On the server side, install with npm:

$ npm install chic

Usage

In Node.js or using Component, you can include Chic in your script by using require:

var Class = require('chic').Class;

If you're just including with a <script>, you're all ready to go. The rest of the examples assume you've got the Class variable already.


Create a class

Creating classes is very simple. You extend the base class like this:

var Animal = Class.extend();

Obviously you want to add methods to your class, to give it some functionality:

var Animal = Class.extend({
    eat:   function () { ... },
    sleep: function () { ... },
    poop:  function () { ... }
});

The init method is a special one. This is your class constructor, and is called when a new instance of your class is created. You can set things up in here.

var Animal = Class.extend({
    init: function () {
        this.alive = true;
    }
});

Instantiating a class

Instantiating your new class is just like instantiating any other JavaScript class now. You'll be able to use all those methods you defined!

var fluffy = new Animal();
fluffy.poop(); // Bad Fluffy!

Extending classes

Any class you create is also extendable. You extend custom classes in exactly the same way as the base class:

var Cat = Animal.extend();

If you define methods in this extend, then they will override methods of the same name which have been inherited from the parent class. For example:

var Animal = Class.extend({
    speak: function () {
        return 'Roar!';
    }
});

var Cat = Animal.extend({
    speak: function () {
        return 'Miaow?';
    }
});

var mrTibbles = new Cat();
mrTibbles.speak(); // Miaow?

If you wish to call the parent method, then that's possible using this.sup, which is a reference to the parent method with the same name as the one being called:

var Animal = Class.extend({
    init: function (name) {
        this.name = name;
    },
    eat: function () {
        return this.name + ' is eating';
    }
});

var Cat = Animal.extend({
    eat: function () {
        return this.sup() + ' like a good kitty';
    }
});

var pet = new Cat('Mr Tibbles');
pet.eat(); // Mr Tibbles is eating like a good kitty

Development

  • Install dependencies with npm install
  • Run tests with npm test
  • Lint code with npm run-script lint

License

Chic is licensed under the MIT license.

Keywords

FAQs

Package last updated on 07 Dec 2012

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