Socket
Socket
Sign inDemoInstall

troop

Package Overview
Dependencies
1
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    troop

Full-featured, testable OOP


Version published
Maintainers
1
Install size
65.5 kB
Created

Readme

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

Last updated on 10 Jul 2015

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc