Friday, 12 May 2017

How to effectively search documentation about JavaScript(NodeJS) object types?

Please explain me how to read this NodeJS docs fs.readFile(file[, options], callback)

In strongly typed language like C++ or Java when I need to get know info about some method argument or return value e.g. System.getProperty which has argument named key and its type (as we can really easily see from the method signature) is String.

  1. I open a class (in our case it's System) in JDK documentation and scroll to a method I interested in.
  2. If I need to know what can I do with the argument or return value (I mean what the methods the argument has and etc.) I simply click on the class String and goto step 1.

So, my question: I'm writing

var fs = require('fs')
fs.readFile(someFile, 'utf8', function (err,data) {
  if (err) {
    return console.log(err);
  }
  var result = data.???
  // is  data.replace(/abc/g, 'xyz') OK? what else???

});

How can I determine the type(do I need the type?) of the data object (first of all I need the list of methods)?

How I supposed to know that the data is probably String consequently it has method replace?

PS: Obviously helpless console.log(typeof data); says it is just an object.



via ieXcept