I was reading through React’s source code which led me to the fbjs npm module which just looks like a bunch of helpful js utilities. I came across a file called emptyObject.js which currently looks like this:
/** * Copyright (c) 2013-present, Facebook, Inc. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @providesModule emptyObject */ 'use strict'; const emptyObject = {}; if (__DEV__) { Object.freeze(emptyObject); } module.exports = emptyObject; Two questions:
- Why use
Object.freeze(...)only in dev mode? - What’s the purpose of this functionality in the first place?
Per the second question above, why not just do something like this:
const myObj = {}; What’s the benefit of
import emptyObject from ‘fbjs/lib/emptyObject’; ... const myObj = emptyObject;