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

attr-accessor

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

attr-accessor

Convenience factories for creating getter/setters

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-90%
Maintainers
1
Weekly downloads
 
Created
Source

Attr Accessor

Version Build Status Dependency Status Code Climate

Convenience factories for creating getter/setters.

Licensed under the MIT license, see LICENSE for more information.

Usage

Pass in an object to attr.reader or attr.writer to obtain a getter or setter factory respectively:

get = attr.reader(object)
set = attr.writer(object)

CoffeeScript has had no elegant way of defining getter/setters, until now. Use its destructuring syntax in combination with attr.accessor to obtain both factories:

[get, set] = attr.accessor(object)

Use attr.accessors when dealing with classes to obtain two prototypal / instance-bound factories as well as two static factories:

[get, set, @get, @set] = attr.accessors(object)

Example

class Person
  [get, set, @get, @set] = attr.accessors(@)

  group = []

  constructor: (@firstName, @lastName) ->
    group.push @

  get name: ->
    "#{@firstName} #{@lastName}"

  @get count: ->
    group.length
new Person('John', 'Doe').name # John Doe
Person.count # 1

Browser Support

Testling

Development & Contribution

When contributing, please:

  • Fork the repository
  • Accompany each logical unit of operation with at least one test
  • Open a pull request
  • Do not include any distribution files

Keywords

FAQs

Package last updated on 21 Sep 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