Object.create() bug?

javascript, oop

Solution

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
  }
});

From the documentation:

If specified and not undefined, an object whose enumerable own properties (that is, those properties defined upon itself and not enumerable properties along its prototype chain) specify property descriptors to be added to the newly-created object, with the corresponding property names. These properties correspond to the second argument of Object.defineProperties.

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.

Problem

``` function create_RowsEditor(tableId, rowTmplId) { rowsEditor = Object.create(null, { 'XtableId': tableId, 'XrowTmplId': rowTmplId }); return rowsEditor; } $(function() { var rowsEditor = create_RowsEditor('come', 'tmpl_row'); }); ``` Error: TypeError: value is not a non-null object Where is the error?

Original source