镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Support custome object #48

Closed as not planned
Closed as not planned

Description

@harvey-woo

Add support for serialization and deserialization of custom objects via Object.assign and Object.create
For example:

class A {
    a = 1
}
serialize(A, { classes: { A } })

get

const serialized = "(function(args) {var k = args[0].classes;return args[0].assign(Object.create(k.A.prototype), { a: 1 })})(arguments)"
function unserialize() {
    return eval(serialized)
}
unserialize({ classes: {A: function() {}}, assign: Object.assign })

Activity

  1. changed the title [-]Support customer object[/-] [+]Support custome object[/+] on Apr 28, 2019
  2. redonkulus commented on Oct 22, 2026

    @redonkulus
    Collaborator

    Restoring custom class instances would require a registry of classes and a custom deserialization step, which is outside this library's scope (it doesn't deserialize). Instances serialize as their own enumerable properties, like JSON.stringify. Closing as won't fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions