How to use JSON to create object that Inherits from Object Type?

前端 未结 3 1073
忘了有多久
忘了有多久 2021-02-02 00:33

I know how to use JSON to create objects, but there doesn\'t seem to be away to use JSON to create an object that is of a specific object type.

Here\'s an example of an

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-02 01:16

    You can derive an object from theirs. Your constructor can accept the object you want, but call their constructor in an unaffected fashion:

    function yourWrapper(obj) {
        theirObject.call(this);
        for (var s in obj) {
            this[s] = obj[s];
        }
    }
    yourWrapper.prototype = new theirObject();
    

    Or something like that :)

提交回复
热议问题