RunKit + npm: smykowski

node v9.11.2
version: 2.0.0
endpointsharetweet
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