node-function-name
Set the "name" property of Function
objects
Very simple module. Sets the non-writable name
property of Function
objects. In older versions of node, this functionality is exposed internally to
V8, but not exposed to JavaScript, so a native module is required. In newer
versions of node, function names can be redefined with Object.defineProperty
,
which this module uses.
Note that unfortunately only String values are allowed.
NOTE: For users of node prior to iojs@3.0.0
, you'll need to use an
earlier version of this module, function-name@1
, which provides a C++
implementation.
Installation
Install with npm
:
$ npm install function-name
Example
var set = require('function-name');
function test () {
throw new Error('blah');
}
console.log(test.name);
set(test, 'foo');
console.log(test.name);
set(test, ' ☃ ');
console.log(test.name);
test();
That's it!