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

new-struct

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

new-struct

Structs inspired from Golang

  • 0.0.1
  • Source
  • npm
  • Socket score

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

new-struct

Structs inspired from Golang

newStruct = require('new-struct')

Animal = newStruct({
  name: '',
  type: '',
  age: 0,
  run: run
})

function run (animal) {
  console.log('%s is running', animal.name)
}

dongdong = Animal('dongdong', 'cat', 4)
blackbear = Animal('blackbear', 'cat', 3)

dongdong.run()
// => dongdong is running

blackbear.run()
// => blackbear is running

Install

$ npm install new-struct

Usage

You can pass the values as an object, too;

dongdong = Animal({ type: 'cat', foobar: 'dfjh' })

Methods can also be defined later;

Animal.method('jump', function(animal){
  console.log('%s is jumping!!', animal.name)
})

To extend an existing struct:

Cat = Animal.extend({
  type: 'cat',
  grrr: grrr
})

function grrr(cat) {
  console.log('grrrrrr')
}

dongdong = Cat('dongdong', 2) // notice how 'type' property got eleminated from parameter order.

To define a constructor method:

Animal = newStruct({
  construct: construct,
  name: '',
  type: '',
  age: 0,
  run: run
})

function construct (animal) {
  animal.log = console.log
  animal.log('%s just born!', animal.name)
}

dondong = Animal('dongdong', 'cat')
// => dongdong just born

Keywords

FAQs

Package last updated on 31 Jul 2013

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