美文网首页
CasperJS is scoped

CasperJS is scoped

作者: RoyTien | 来源:发表于2017-06-06 16:55 被阅读2次

In CasperJS, global variable cannot be accessed inside function.
The following code will return null

var globalVar;

function myFunction(){
  globalVar = 1;
  return globalVar;
}

echo(myFunction());

Output: null

The following code works

var globalVar;
function myFunction(){
  var localVar = 1;
  return localVar;
}

globalVar = myFunction();
echo(globalVar);

Output: 1

相关文章

网友评论

      本文标题:CasperJS is scoped

      本文链接:https://www.haomeiwen.com/subject/trbgfxtx.html