Serialize JavaScript object into JSON string

后端 未结 8 1660
广开言路
广开言路 2020-12-23 15:49

I have this JavaScript prototype:

Utils.MyClass1 = function(id, member) {
this.id = id;
this.member = member;
}

and I create a new object:<

8条回答
  •  抹茶落季
    2020-12-23 16:35

    You can use a named function on the constructor.

    MyClass1 = function foo(id, member) {
        this.id = id;
        this.member = member;
    }
    
    var myobject = new MyClass1("5678999", "text");
    
    console.log( myobject.constructor );
    
    //function foo(id, member) {
    //    this.id = id;
    //    this.member = member;
    //}
    

    You could use a regex to parse out 'foo' from myobject.constructor and use that to get the name.

提交回复
热议问题