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

classic

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

classic

Straightforward classes for node.js or web browsers

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
206
increased by131.46%
Maintainers
1
Weekly downloads
 
Created
Source

classic

Straightforward classes for node.js or web browsers

Installation

npm install --save classic

Usage

var classic = require('classic');


// Using function invoked with the prototype as 'this'
var Person = classic(function() {
  this.constructor = function(firstname, lastname) {
    this.firstname = firstname;
    this.lastname = lastname;
  };

  this.name = function() {
    return this.firstname + ' ' + this.lastname;
  };
});
var p = new Person('john', 'doe');
p.name(); // 'john doe'
p instanceof Person; // true


// Passing the prototype directly and a superclass as second argument
var Actor = classic({
  constructor: function(firstname, lastname, movieCount) {
    Person.apply(this, arguments);
    this.movieCount = movieCount;
  },

  name: function() {
    return Person.prototype.name.call(this) + ', acted in ' +
      this.movieCount + ' movies';
  }
}, Person);
var a = new Actor('john', 'travolta', 42);
a.name(); // 'john travolta, acted in 42 movies'
p instanceof Person && p instanceof Actor; // true


// Every class created has an 'extend' method that may be used instead of
// passing the superclass as second argument. Constructors may also be
// omitted(the superclass constructor is invoked with the passed  arguments)
var Director = Actor.extend(function() {
  this.name = function() {
    return Person.prototype.name.call(this) + ', directed ' +
      this.movieCount + ' movies';
  };
});
var d = new Director('quentin', 'tarantino', 42);
d.name(); // 'quentin tarantino, directed 42 movies'
p instanceof Person && p instanceof Actor && p instanceof Director; // true

Keywords

FAQs

Package last updated on 08 Oct 2013

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