new Settable()
A base class which gives instances private properties.
Typically you won't instantiate this class directly, but you may find it useful as an abstract class for your own components.
See Settable.extend for an example of using Settable as a base class.
import {Settable} from 'js-data'
Details
Since | Source |
---|---|
3.0.0 | Settable.js, line 3 |
Methods
-
<static> extend(props, classProps)
-
Create a subclass of this Settable:
Method parameters:Name Type Argument Default Description props
Object <optional>
{} Properties to add to the prototype of the subclass.
Properties
Name Type Argument Description constructor
Object <optional>
Provide a custom constructor function to be used as the subclass itself.
classProps
Object <optional>
{} Static properties to add to the subclass.
Return value:Type Description Constructor Subclass of this Settable class.
DetailsSince Source 3.0.0 Settable.js, line 61 Example// Normally you would do: import {Settable} from 'js-data' const JSData = require('js-data@3.0.0-beta.7') const {Settable} = JSData console.log('Using JSData v' + JSData.version.full) // Extend the class using ES2015 class syntax. class CustomSettableClass extends Settable { foo () { return 'bar' } static beep () { return 'boop' } } const customSettable = new CustomSettableClass() console.log(customSettable.foo()) console.log(CustomSettableClass.beep()) // Extend the class using alternate method. const OtherSettableClass = Settable.extend({ foo () { return 'bar' } }, { beep () { return 'boop' } }) const otherSettable = new OtherSettableClass() console.log(otherSettable.foo()) console.log(OtherSettableClass.beep()) // Extend the class, providing a custom constructor. function AnotherSettableClass () { Settable.call(this) this.created_at = new Date().getTime() } Settable.extend({ constructor: AnotherSettableClass, foo () { return 'bar' } }, { beep () { return 'boop' } }) const anotherSettable = new AnotherSettableClass() console.log(anotherSettable.created_at) console.log(anotherSettable.foo()) console.log(AnotherSettableClass.beep())
-
_get(key)
-
Get a private property of this instance.
Don't use the method unless you know what you're doing.
Method parameters:Name Type Description key
String The property to retrieve.
Return value:Type Description * The value of the property.
DetailsSince Source 3.0.0 Settable.js, line 23