Clone and edit this document
Runkit
Runkit
home page
user forum
new notebook
clone notebook
download notebook
support & documentation
log in
sign up
new notebook
help & feedback
clone this notebook
download this notebook
Sign In
Sign Up
RunKit + npm: smykowski
node v9.11.2
version:
2.0.0
endpoint
share
tweet
const { Smykowski, defaultEncoders, defaultDecoders, classSerializer } = require("smykowski@1.2.0"); class Person { constructor(first, last) { this.first = first; this.last = last; } getFullname() { return this.first + ' ' + this.last; } } class Employee extends Person { constructor(first, last, id) { super(first, last); this.id = NaN; } } const ajson = new Smykowski() .use(classSerializer, { Person, Employee }) .use(defaultEncoders) .use(defaultDecoders);
Created from: https://npm.runkit.com/smykowski
const str = ajson.stringify([ new Person('John', 'Doe'), new Employee('Jane', 'Doe', 'A123') ]); const [ john, jane ] = ajson.parse(str); console.assert(john instanceof Person); // true console.assert(jane instanceof Employee); // true console.log(jane.getFullname(), jane.id); // "Jane Doe", NaN
Loading…
no comments
sign in
to comment