Socket
Socket
Sign inDemoInstall

creatorpattern.js

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    creatorpattern.js

microlib to easily add the creator pattern to your class.


Version published
Weekly downloads
4
increased by33.33%
Maintainers
1
Install size
3.96 kB
Created
Weekly downloads
 

Readme

Source

creatorpattern.js

microlib to easily add the creator pattern to your class. It works in browser and node.js

how to use it

to mixin the creator pattern in a class ```FooClass`, do the following in node.js

var mixinCreatorPattern = require('creatorpattern');
mixinCreatorPattern(FooClass, 'FooClass')

or do the following in your browser

mixinCreatorPattern(FooClass, 'FooClass')

After that, FooClass honor the creator pattern. so instead of

var foo = new FooClass(2,1)

you can do

var foo	= FooClass.create(2,1);

how to include it

in node.js

 npm install creatorpattern.js

in your browser

 <script src='creatorpattern.js'></script>

api

It includes a single function mixinCreatorPattern(constructorFunction, nameOfClass)

mixinCreatorPattern(FooClass, 'FooClass')
  • the first parameter FooClass is the contructor of your class.
  • The second parameter 'FooClass' is optional and is the name of the class in string. It does its best to keep the name of the class. Thus when you display your variables in the js console, you will see the proper name. If the name isn't provided, it will take the function name of the constructor function. If there is none, the name won't be kept

Keywords

FAQs

Last updated on 23 Apr 2013

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