将对象传递给函数不起作用。
function getSecret(file, secretPassword){
file.opened = file.opened + 1;
if(secretPassword == file.password){
return file.contents;
}
else {
return "Invalid password! No secret for you";
}
}
function setSecret(file, secretPassword, secret){
if(secretPassword == file.password){
file.opened = 0;
file.contents = secret;
}
}
var superSecretFile = {
level: "classified",
opened: 0,
password: 2,
contents: "Dr. Evel's next meeting is in Detroit."
};
var secret = getSecret(superSecretFile, superSecretFile.password);** why superSecretFile.password is not passing the value 2
console.log(secret);
setSecret(superSecretFile,2, "Dr. Evel's next meeting is in Philadelphia.");
secret = getSecret(superSecretFile, superSecretFile.password);
console.log(secret);
我传递一个对象作为参数。如果我放superSecretFile.password
,此代码无效。为什么不呢?