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

troop

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

troop

Full-featured, testable OOP

  • 0.9.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
10
increased by233.33%
Maintainers
1
Weekly downloads
 
Created
Source

Troop

Full-featured, testable OOP

Wiki

Reference

Troop features

  • multiple inheritance with traits
  • makes use of ES5 property attributes
    • pseudo-privates are non-enumerable
    • constants are actually read-only
  • testing mode for applying mock methods
  • postponed, on-demand property definitions
  • delegation of instantiation with surrogates
  • support for instance memoization

Troop is distinguished from other OOP-related libs such as MooTools or Backbone by

  • not littering your classes and instances with its own meta-properties
  • non-declarative API leads to better IDE integration
  • offering simpler unit testing with built-in mocks to speed up TDD process

Example

var MyClass = troop.Base.extend()
    .addPrivate({
        _secret: "ufo" // static private property
    })
    .addPublic({
        hello: "world" // static public property
    })
    .addConstants({
        pi: 3.14 // static public constant
    })
    .addMethods({
        init: function (who) {
            this.addPublic({
                hello: who
            });
        }
    });

var myInstance = MyClass.create("all");

myInstance in console

Check out these jsFiddles for more examples:

Keywords

FAQs

Package last updated on 10 Jul 2015

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