为什么用空对象扩展函数?

时间:2017-03-19 14:31:54

标签: javascript

我正在查看Rebound javascript code并看到var SpringSystem = rebound.SpringSystem = function SpringSystem() { this._springRegistry = {}; this._activeSprings = []; this._listeners = []; this._idleSpringIndices = []; this._boundFrameCallback = bind(this._frameCallback, this); }; extend(SpringSystem, {}); 函数正在使用空对象进行扩展。

extend

function extend(target, source) { for (var key in source) { if (source.hasOwnProperty(key)) { target[key] = source[key]; } } } 的样子:

extend

第一个hasOwnProperty(key)通过扩展空对象实现了什么?我的理解是空对象没有任何 `String fileName = "productData.txt"; String line = null; try { FileReader fileReader = new FileReader(fileName); BufferedReader bufferedReader = new BufferedReader(fileReader); while((line = bufferedReader.readLine()) != null) { System.out.println(line); } bufferedReader.close(); } catch(FileNotFoundException e) { System.out.println(e); } catch(IOException e) { e.printStackTrace(); }`

我错过了什么?

1 个答案:

答案 0 :(得分:4)

你什么都不缺,代码没有任何意义。它看起来像是类模板中的剩余部分,请注意其他类和所有原型都使用此模式。

这也是为什么it has been removed in 2014