-
Notifications
You must be signed in to change notification settings - Fork 79
Node.js programming
bellbind edited this page Oct 25, 2013
·
5 revisions
As as module exports, to provide a wrapped JS function to call the constructor with new
. e.g.
var nativemod = require("build/Release/mynativemod");
exports.Ctor = function () {
return new nativemod.Ctor();
};
If usual functions, you can use apply
or call
and arguments
for forwarding wrapped functions.
For wrapping constructors, combine with ECMAScript5 bind
as:
var WrapperCtor = function Ctor() {
var args = [null].concat([].slice.call(arguments));
var ctor = RawCtor.bind.apply(RawCtor, args);
return new ctor;
};
note: wrap constructor with explicit arguments
var WrappedCtor = function Ctor(arg1, arg2) {
var ctor = RawCtor.bind(null, arg1, arg2);
return new ctor;
};
Generic version is switched bind
call with apply
and arguments
.