How do I access the Object.prototype method in the following logic?

前端 未结 4 581
一个人的身影
一个人的身影 2020-12-23 14:24

I am using the following logic to get the i18n string of the given key.

export function i18n(key) {
  if (entries.hasOwnProperty(key)) {
    return entries[k         


        
4条回答
  •  天命终不由人
    2020-12-23 14:59

    For your specific case, the following examples shall work:

    if(Object.prototype.hasOwnProperty.call(entries, "key")) {
        //rest of the code
    }
    

    OR

    if(Object.prototype.isPrototypeOf.call(entries, key)) {
        //rest of the code
    }
    

    OR

    if({}.propertyIsEnumerable.call(entries, "key")) {
        //rest of the code
    }
    

提交回复
热议问题