1

I'm writing some code that will do some introspection on a Function in node. Specifically, I want to hopefully do non-standard-JS things like listing source code line numbers. However, there appears to be no reference documentation available on global types in node/v8 to see what's available.

The Global Objects documentation for node doesn't have this information. Although MDN documents Function, it only lists standard methods/properties or its own non-standard extensions. Also, its compatibility chart focuses on browser JS engines. It helped me find the name property of a function at least.

The REPL isn't helping me either:

> function foo() { }
undefined
> foo
[Function: foo]
> console.dir(foo)
[Function: foo]
undefined
> Object.keys(foo)
[]
> Object.keys(Function.prototype)
[]
>

Is there any sort of reference documentation for global node types?

4
  • What do you mean, "global node types"? Do you expect there to be any non-standard methods? Commented Apr 2, 2015 at 17:05
  • Tip: Use Object.getOwnPropertyNames instead of keys Commented Apr 2, 2015 at 17:06
  • Are you planning to write some native code or how do you think introspection will be possible? Commented Apr 2, 2015 at 17:07
  • I hoped there was a non-standard method available, but as getOwnPropertyNames shows, I'm SOL. Oh well. Commented Apr 2, 2015 at 18:28

1 Answer 1

1
function allProps(obj, name = '') {
     if (obj == null) return; // recursion to the final link in this prototype chain
     console.log(name, Object.getOwnPropertyNames(obj));
     allProps(Object.getPrototypeOf(obj), 'prototype');
}

allProps(Function, 'Function');
allProps(Function.prototype, 'Function.prototype');
allProps(Function.__proto__, 'Function.__proto__');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.