|
|
@ -143,32 +143,6 @@ Changes the current working directory of the process or throws an exception if t |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
### process.compile(code, filename) |
|
|
|
|
|
|
|
Similar to `eval` except that you can specify a `filename` for better |
|
|
|
error reporting and the `code` cannot see the local scope. The value of `filename` |
|
|
|
will be used as a filename if a stack trace is generated by the compiled code. |
|
|
|
|
|
|
|
Example of using `process.compile` and `eval` to run the same code: |
|
|
|
|
|
|
|
var localVar = 123, |
|
|
|
compiled, evaled; |
|
|
|
|
|
|
|
compiled = process.compile('localVar = 1;', 'myfile.js'); |
|
|
|
console.log('localVar: ' + localVar + ', compiled: ' + compiled); |
|
|
|
evaled = eval('localVar = 1;'); |
|
|
|
console.log('localVar: ' + localVar + ', evaled: ' + evaled); |
|
|
|
|
|
|
|
// localVar: 123, compiled: 1 |
|
|
|
// localVar: 1, evaled: 1 |
|
|
|
|
|
|
|
`process.compile` does not have access to the local scope, so `localVar` is unchanged. |
|
|
|
`eval` does have access to the local scope, so `localVar` is changed. |
|
|
|
|
|
|
|
In case of syntax error in `code`, `process.compile` exits node. |
|
|
|
|
|
|
|
See also: `Script` |
|
|
|
|
|
|
|
|
|
|
|
### process.cwd() |
|
|
|
|
|
|
|