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

bloody-class

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

bloody-class

[![browser support](https://ci.testling.com/bloodyowl/class.png)](https://ci.testling.com/bloodyowl/class)

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
Maintainers
1
Weekly downloads
 
Created
Source

class

browser support

Install

$ npm install bloody-class

With component(1):

$ component install bloodyowl/class

Require

var klass = require("class")

Definition

Classes are objects that contain inherits for instances. You can extend and create instances of an existing class. Classes are based on prototypal inheritance, that way, you can easily update all subclasses and instances from one of their parent class.

Methods

klass.extend([object]) -> newClass

Creates a new class that inherits from klass. Optionaly takes an object arguments that extends the newClass as owned properties.

klass.create([args …]) -> newInstance

Creates a new instance that inherits from klass. Its arguments are passed to klass.constructor which is called if klass owns a constructor method.

instance.destroy([args …])

Removes all the internal references to instance, as in parent.instances for instance. Its arguments are passed to klass.destructor which is called if klass owns a destructor method.

Usage

// create a class
var myClass = klass.extend({
  // constructor is the method called when an instance is created
  constructor : function(args/* …*/){ 
    // this -> instance
    // args … -> arguments passed through the `.create` method
  }, 
  destructor : function(){
    // this -> instance
    // args … -> arguments passed through the `.destroy` method
  }
})

// myClass has a "_klass" property with a uniq integer
myClass._klass // -> integer

// create an instance
var myInstance = myClass.create()

// myInstance has a "_id" property with a uniq integer (relative to its parent class)
myInstance._id // -> integer

// instance is in myClass._instances and myInstance._instances
each(myClass._instances, console.log, console)
// > logs [myInstance, "0", myClass._instances]

// destroy an instance
myInstance.destroy()

// instance is now removed from myClass._instances
each(myClass._instances, console.log, console)
// > doesn't log anything

// and wipe it out
myInstance = null

FAQs

Package last updated on 07 Jan 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