Wednesday, 3 May 2017

fs.js module in nodejs requiring itself?

I'm currently learning nodeJS and running version v6.10.2, I was taking a look at the fs.js module source code located in the graceful-js folder and noticed this code in it:

'use strict'

var fs = require('fs')

module.exports = clone(fs)

function clone (obj) {
  if (obj === null || typeof obj !== 'object')
    return obj

  if (obj instanceof Object)
    var copy = { __proto__: obj.__proto__ }
  else
    var copy = Object.create(null)

  Object.getOwnPropertyNames(obj).forEach(function (key) {
    Object.defineProperty(copy, key, Object.getOwnPropertyDescriptor(obj, key))
  })

  return copy
}

How can a module require itself does it have to do with the clone keyword? I couldn't find any other module named fs.js either.



via DanT29

No comments:

Post a Comment