Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Object.create() bug?

Tags:

javascript

oop

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?

like image 325
porton Avatar asked May 18 '26 02:05

porton


1 Answers

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.

like image 141
Felix Kling Avatar answered May 19 '26 16:05

Felix Kling



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!