Javascript没有将某些变量传递给子函数

时间:2014-02-20 20:27:33

标签: javascript node.js

我不确定为什么会这样,但只有某些变量没有传递到子函数范围,例如(在nodejs中):

var json        = {some:'json'},
    pem         = require('pem'),
    ursa        = require('ursa'),
    sha256      = crypto.createHash('sha256'),
    _key        = 'a string',
    _iv         = 'a string',
    cipher      = crypto.createCipheriv( 'aes-256-cbc' , _key , _iv ),
    cert        = 'a string';

pem.getPublicKey(cert,function(err,publicKey){

        //AES Write
        cipher.write(new Buffer('string'),'utf8',function(err){ });

        //End AES Encryption
        cipher.end();

        //On AES Receive Data
        cipher.on('data', function(string){
            console.log( 'JSON: ', json ); //Works
            console.log( 'PEM: ', pem ); //Works
            console.log( 'Ursa: ', ursa ); //Works
            console.log( 'sha256: ', sha256 ); //Undefined
            console.log( '_key: ', _key ); //Works
            console.log( '_iv: ', _iv ); //Works
            console.log( 'cipher: ', cipher ); //Works
            console.log( 'cert: ', cert ); //Works
            console.log( 'publicKey: ', publicKey ); //Undefined
        });
});

为什么只传递一些变量,而其他变量未定义?

1 个答案:

答案 0 :(得分:0)

这些库的变量名称可能是保留的关键字。