I have someScript.js which requires several node parameters to work properly. For example. (let us have node 0.12.7):
node --harmony someScript.js
I want to run it without the -harmony option and somehow install it inside the script.
I tried changing process.execArgv:
process.execArgv.push('--harmony');
function getGenerator() {
return function *() {
yield 1;
};
}
var gen = getGenerator();
Since NodeJS is an interpreter, it can allow such changes (even on the fly). But, NodeJS seems to ignore the changes to process.execArgv.
Also I tried v8.setFlagsFromString:
Interestingly, all versions of NodeJs that needed settings to support generators do not contain the v8 module. So, I experimented with NodeJS 4.1.1
var v8 = require('v8');
var vm = require('vm');
v8.setFlagsFromString('--harmony');
var str1 =
'function test1(a, ...args) {' +
' console.log(args);' +
'};';
var str2 =
'function test2(a, ...args) {' +
' console.log(args);' +
'};';
eval(str1);
test1('a', 'b', 'c');
vm.runInThisContext(str2);
test2('a', 'b', 'c');
Unfortunately, it v8.setFlagsFromString('--harmony')didn’t help, even for eval () and vm.runInThisContext ().
script.
, nodejs- javascript?