每次我返回变量时都调用一个函数吗? [英] call a function every time i return a variable?

查看:56
本文介绍了每次我返回变量时都调用一个函数吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到在Google ,每次您在javascript控制台上输入变量时,它们都会调用一个函数.

I've noticed that in the Google text adventure game easter egg they have a function call everytime you enter in a variable on the javascript console.

这是怎么做的?

推荐答案

它不适用于任意变量.它不适用于任意表达式.它仅适用于给定的命令(是,否,北,南,东,西,上,下,抓取,原因,清单,使用,帮助,退出,地图和朋友).

It doesn't work for arbitrary variables. It doesn't work for arbitrary expressions. It only works for those commands that are given (yes, no, north, south, east, west, up, down, grab, why, inventory, use, help, exits, map, and friends).

对于变量来说,它实际上并不起作用.输入 yes 时得到的是全局 window.yes 属性-他们已经为它定义了一个吸气剂.将对该吸气剂进行评估,返回字符串"yes" ,然后将下一个输出异步记录到控制台.

It doesn't really work for variables anyway. What you get when you enter yes is the global window.yes property - and they have defined a getter for it. This getter will be evaluated, return the string "yes", and asynchronously log the next output to the console.

这篇关于每次我返回变量时都调用一个函数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆