new-prop

Minimalistic, extendible properties

Minimalistic, extendible property library for JavaScript

PI = prop(3.14)
PI()
// => 3.14 
 
PI(3.14159)
PI()
// => 3.14159 
$ npm install new-prop # component install adaio/prop
foo = prop(3.14)
  .extend(function(raw){
 
    return function(newValue){
      
      if(newValue){
        newValue*=10
        return raw(newValue)
      }
 
      return raw()
    }
 
  })

Sets a getter function for the property.

foo = prop()
  .getter(function(value){
    return value + '.00$'
  })
 
foo(314)
 
foo()
// => 314.00$ 
 
foo.raw()
// => 314 

Sets a setter function for the property.

foo = prop()
  .setter(function(value){
    return value + '.00$'
  })
 
foo(314)
 
foo()
// => 314.00$ 
 
foo.raw()
// => 314.00$