Object.create()bug? [英] Object.create() bug?

查看:78
本文介绍了Object.create()bug?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

function create_RowsEditor(tableId, rowTmplId) {
  rowsEditor = Object.create(null, {
    'XtableId': tableId,
    'XrowTmplId': rowTmplId
  });
  return rowsEditor;
}

$(function() {
  var rowsEditor = create_RowsEditor('come', 'tmpl_row');
});

错误:TypeError:value不是非空对象

Error: TypeError: value is not a non-null object

错误在哪里?

推荐答案

你不能将任意对象作为第二个参数传递,它必须是属性描述符的对象。例如:

You cannot pass an arbitrary object as second parameter, it has to be an object of property descriptors. For example:

rowsEditor = Object.create(null, {
  'XtableId': {
      value: tableId
  },
  'XrowTmplId': {
      value: rowTmplId
  }
});

来自 documentation


如果指定且未定义,则为对象的可枚举属性(即,自身定义的属性,而不是沿其原型链的可枚举属性)指定要添加到新创建的对象的属性描述符,以及相应的属性名称。这些属性对应于 Object.defineProperties 的第二个参数。

有关属性描述符结构的详细信息,请参阅 Object.defineProperty documentation 。如上面的代码所示,属性指定属性的值。

Detailed information about the structure of property descriptors can be found in the Object.defineProperty documentation. As shown in the code above, the value property specifies the value of the property.

这篇关于Object.create()bug?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆