Object.defineProperty抛出错误,因为未定义config

时间:2016-03-04 21:46:18

标签: javascript

我正在阅读Addy Osmani的书籍JavaScript设计模式,为什么当它不起作用时他会使用这样的配置?

var defineProp = function ( obj, key, value) {
  config.value = value;
  Object.defineProperty(obj, key, config);
}

var man = Object.create(null);

defineProp( man, 'car', 'Delorean');
defineProp( man, 'dob', '1981');
defineProp( man, 'beard', false);

// As we will see a little later in the book, these methods can even be used for inheritance, as follows:

var driver = Object.create(man); 
defineProp(driver, 'topSpeed', '100mph');
driver.topSpeed // 100mph

0 个答案:

没有答案