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

abstract-object

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

abstract-object

AbstractObject with Object State Events Support, RefObject with RefCount and AddRef/Release Support.

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
33
increased by135.71%
Maintainers
1
Weekly downloads
 
Created
Source

AbtractObject

Build Status

NPM NPM

AbstractObject with Object State Events Supports and free method provides.

The derived class should overwrite the init, final methods.

  • Methods:

    • create(class): the create class method uses to create a new object instance.
      • class: the class constructor to create a new instance.
      • ...: the left arguments will be passed into the constructor.
    • init: abstract initialization method after a new instance creating.
      • the constructor's arguments should be passed into init method.
    • final: abstract finalization method before the instance destroying.
    • free: free the class instance.
  • Events:

    • 'initing': emit before the init method
    • 'inited': emit after the init method
    • 'destroying': emit before the final method
    • 'destroyed': emit after the final method

RefObject

The RefObject is derived from AbstractObject. and add the RefCount and AddRef/Release Supports.

  • methods:
    • release/free: Decrements reference count for this instance. If it is becoming less than 0, the object would be (self) destroyed.
    • addRef: Increments the reference count for this instance and returns the new reference count.

Usage:

AbstractObject = require('abstract-object')
RefObject = require('abstract-object/RefObject')
inherits = require('abstract-object/lib/util').inherits

class MyObject
  inherits MyObject, RefObject
  init: (@a,@b)->
    super()

myObj = AbstractObject.create(MyObject, 1, 2)

# if you do not wanna use `AbstractObject.create`, you MUST remember this:
# even the constructor is empty, you should can the parent's constructor manually.

class MyObject
  inherits MyObject, RefObject
  constructor: ->
    super
  init: (@a,@b)->
    super()



the javascript:


var AbstractObject = require('abstract-object')
var RefObject = require('abstract-object/RefObject')
var util = require('abstract-object/lib/util')

//if you do not wanna to use the 'AbstractObject.create':
var MyObject = function() {
  //super call
  MyObject.__super__.constructor.apply(this, arguments);
}
// or, this MUST use 'AbstractObject.create'
var MyObject = function(){}


util.inherits(MyObject, RefObject)


MyObject.prototype.init = function(a,b) {
  //super call
  MyObject.__super__.init.call(this);
  this.a = a
  this.b = b
}


var myObj = AbstractObject.create(MyObject, 1, 2)

Keywords

FAQs

Package last updated on 16 Dec 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