문제

How can I create an object like this in JS since public and private are reserved words

keyObject = {
    public : {
        iv: "123",
        key: "123"
    },   
    private : {
        key: "123"
   }
}
도움이 되었습니까?

해결책

Quote the keys, like this:

var keyObject = {
    "public" : {
        iv: "123",
        key: "123"
    },
    "private" : {
        key: "123"
    }
}

http://jsfiddle.net/5tUXy/

다른 팁

you can define keys as strings

keyObject {
    'public': {
        iv: "123",
        key: "123"
    },
    'private': {
        key: "123"
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top