Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Chic is an extremely simple class-like interface to JavaScript prototypal inheritance
Chic is an extremely simple class-like interface to JavaScript prototypal inheritance.
Current Stable Version: 1.0.2
Automated Build Status:
Node Support: 0.6, 0.8
Browser Support: Android Browser 2.2–4.2, Firefox 3.6, Firefox 4–16, Google Chrome 14–23, Internet Explorer 6–10, Mobile Safari iOS 4–6, Opera 12.10, Safari 5–6
You can use Chic on the server side with Node.js and npm:
$ npm install chic
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>
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>
, Class
is available in the chic
namespace:
var Class = chic.Class;
The rest of the examples assume you've got the Class
variable already.
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 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!
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
This feature is planned, and will be introduced in the near future. In the meantime, @jhnns has this functionality working in his fork.
To develop Chic, you'll need to clone the repo and install dependencies:
$ npm install
No code will be accepted unless all tests are passing and there are no lint errors. Commands are outlined below:
Run JSHint with the correct config against the code-base:
$ make lint
Run unit tests on the command line in a Node environment:
$ make test
To run unit tests in supported browsers, you need to run a small express app to serve the files (this bundles test together to make managing them a lot easier):
$ make test-server
Now you will be able to visit http://localhost:3893/
in your browsers to run the tests. The app will automatically restart whenever a JavaScript file changes locally, so re-running the tests is just a case of reloading the page.
Unfortunately, my testing tools don't work correctly in Firefox 3.6 and IE 6–8. Because of this, there is a stripped down test suite available on http://localhost:3893/legacy
which caters for these browsers.
This library was inspired by John Resig's great Simple JavaScript Inheritance post.
Chic is licensed under the MIT license.
FAQs
Chic is an extremely simple class-like interface to JavaScript prototypal inheritance
The npm package chic receives a total of 3 weekly downloads. As such, chic popularity was classified as not popular.
We found that chic demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.