`
my201my
  • 浏览: 9351 次
最近访客 更多访客>>
社区版块
存档分类
最新评论

测试你的JavaScript能力?

 
阅读更多

测试你的JavaScript能力?
2010年09月07日
  今看到一篇国外测试JS的题目,做了下,结果让人汗颜! 看来JS还有好多要学...... 地址:http://perfectionkills.com/javascript-quiz/
  司徒正美的答案解析:http://www.cnblogs.com/rubylouvre/archive/2010/02/ 13/1667565.html
  1. (function(){ return typeof arguments; })();   答案: object
  arguments是一个类似数组但不是数组的对象,说它类似(仅仅是类似)数组是因为其具有数组一样的访问性质及方式,可以由 arguments[n]来访问对应的单个参数的值,并拥有数组长度属性length。还有就是arguments对象存储的是实际传递给函数的参数,而不局限于函数声明所定义的参数列表(用funcName.length取),而且不能显式创建 arguments 对象。arguments 对象只有函数开始时才可用。
  http://www.cnblogs.com/sharplife/archive/2006/12/3 1/608941.html
  2.  var f = function g(){ return 23; }; typeof g(); 答案: erro
  3. (function(x){ delete x; return x; })(1); 答案: 1
  delete expression  从对象中删除一个属性,或从数组中删除一个元素。
  expression 参数是一个有效的 JScript 表达式,通常是一个属性名或数组元素。 
  说明
  如果 expression 的结果是一个对象,且在 expression 中指定的属性存在,而该对象又不允许它被删除,则返回 false。在所有其他情况下,返回 true。
  4. var y = 1, x = y = typeof x; x; 答案: undefined 
  5. (function f(f){ return typeof f(); })(function(){ return 1; }); 答案: number
  函数名被优先级更高的参数名覆盖了
  This function calls itself f - but it also calls its first argument f. Who wins? The argument does. 'nuff said. It's important to understand that this is not a closure variable. Instead, it is determined at function-run-time, by the entity which it 'belongs to' at the time - and if there is no such object, then the object is window. So if you call foo.bar(), then this will point at foo. But when you call arguments[0](), it points at arguments instead. Since arguments.baz is undefined, you get this particular behaviour. Since the assignment to global variable f makes this function not belong to any entity, this points to window and the result is again "undefined" - unless you habitually set window.baz. The operator , is like the keyword function - it has its fingers in many pies. Usually, commas are used as a syntactic element in var statements, function arguments, and object/array notations. But the humble comma is also an operator in its own right - a left-associative operator which returns the value on its right. (By virtue of being lower-precedence than =, comma is the lowest-precedence operator, as well.) As we now know, the g() syntax just establishes something which the function calls itself - but the function is anonymous to everyone else until assigned a variable. Thus, the second function here is selected by the comma, and it is immediately run. This makes the assignment equivalent to var f = 2;. They don't actually let you answer the first thing that came to my mind, which was "ReferenceError." It turns out that typeof x doesn't generate ReferenceErrors when x is not a valid variable in the local codespace. In any case, the above comments about function operators not being function statements - and thus not defining a variable f in the local scope - causes f to be an invalid variable within that scope. Thus, its typeof is "undefined".  函数声明只能裸露于全局作用域下或位于函数体中。从句法上讲,它们不能出现在块中,例如不能出现在if、while 或 for 语句中。因为块只能包含语句,因此if()中的f函数不能当做函数声明,当成表达式使用可能在预编译阶段做了如下处理 if((XXX = function(){}))因此我们是找不到f的 This is easier than it has to be: typeof always returns strings. Essentially, we're asked to evaluate typeof typeof typeof y - which, rather than throwing a ReferenceError, gives "string".  If the argument to the function were {bar: 1}, then this would return "number". However, the argument is {foo: {bar: 1}}, and thus the bar on the root object is undefined. The inner two usages of function are statements which begin with the keyword function - hence they are function statements, not function operators. Function statements float towards the top of their codespace. This is sometimes called "hoisting". Unlike the var statement, which floats the variable declarations but not assignments toward the top of the codespace, the whole function body goes with it.  When you return an object (other than null) or a function from a constructor, this return value overrides the constructor's normal output. In this case, we have the egotistical function f, which always returns itself. Trying to construct an object via new f() will simply return f itself. Since new f() is not an object, then, it's not an instance of anything. (Actually, that's a lie. Functions are secretly objects, and f instanceof Function evaluates to true. This also means that you could set, for example, f.foo = "bar" without impunity.) A function's length is its number of expected (named) arguments. The use of undefined here is not actually a syntax error, because undefined can actually be redefined to a value other than void(0). It is a valid token, if an unusual one.
分享到:
评论

相关推荐

    javascript经典特效---测试心算能力.rar

    测试心算能力.rar测试心算能力.rar测试心算能力.rar测试心算能力.rar测试心算能力.rar测试心算能力.rar

    javascript经典特效---测试反应能力.rar

    测试反应能力.rar测试反应能力.rar测试反应能力.rar测试反应能力.rar测试反应能力.rar测试反应能力.rar

    masterasptest:Javascript能力测试

    大师测试Javascript能力测试

    《JavaScript脚本特效编程给力起飞》

    因此本巴士还在最后张贴了Web测试的知识,引入了网页调试工具Firebug,并介绍了它的使用,让你不仅能够掌握JavaScript的知识,还能学到网页测试方面的内容,从而全面提高自身能力。 本书结合了丰富的开发经验及体会...

    JavaScript开发的微信小程序心理测试源码.zip

    JavaScript开发的微信小程序心理测试源码.zipJavaScript开发的微信小程序心理测试源码.zipJavaScript开发的微信小程序心理测试源码.zipJavaScript开发的微信小程序心理测试源码.zipJavaScript开发的微信小程序心理...

    adobe-test:完成javascript能力测试

    土坯测试完成javascript能力测试。

    JavaScript核心概念及实践 高清PDF扫描版 (邱俊涛).pdf

    《JavaScript核心概念及实践》不仅帮助读者迅速掌握JavaScript基础知识和核心技术,而且通过实例讲解如何将这些知识和技术理解应用到实际工作中,提升编程能力,以简洁、优美的代码开发出功能强大且更易于维护和扩展...

    jmeter 测试工具 使用java自测 并发测试 环境测试 压力测试

    1.可链接的取样器允许无限制的测试能力。 2.各种负载统计表和可链接的计时器可供选择。 3.数据分析和可视化插件提供了很好的可扩展性以及个性化。 4.具有提供动态输入到测试的功能(包括Javascript)。 5.支持脚本...

    JavaScript脚本特效编程给力起飞

    你即将有机会坐上网页特效设计大巴...因此本巴士还在最后张贴了Web测试的知识,引入了网页调试工具Firebug,并介绍了它的使用,让你不仅能够掌握JavaScript的知识,还能学到网页测试方面的内容,从而全面提高自身能力。

    dojo是JavaScript语言实现的开源DHTML工具

     Dojo能够让你更容易使Web页面具有动态能力,或者在任何能够稳定支持JavaScript语言的环境中发挥作用。  Dojo有以下的特征:  1、利用Dojo提供的组件,你可以提升你的web应用程序可用性、交互能力以及功能上的...

    Javascript经典正则表达式

    1,正则表达式,可以说是任何一种编程语言都提供的机制,它主要是提供了对字符串的处理能力。 2,正则表达式在页面处理中的使用场景: 1)表单验证。验证某些域符合某种规则,例如邮件输入框必须输入的是邮件、联系...

    基于JavaScript的大学生心理健康系统源码.zip

    基于JavaScript的大学生心理健康系统源码.zip基于JavaScript的大学生心理健康系统源码.zip基于JavaScript的大学生心理健康系统源码.zip基于JavaScript的大学生心理健康系统源码.zip基于JavaScript的大学生心理健康...

    [JavaScript.DOM高级程序设计](加)桑贝斯.扫描版.part1.rar

     9.2 增强DOM操作能力   9.2.1 连缀语法   9.2.2 通过回调函数进行过滤   9.2.3 操纵DOM文档   9.3 处理事件   9.3.1 注册事件   9.3.2 自定义事件   9.4 访问和操纵样式   9.5 通信   ...

    Testable JavaScript

    这本书告诉你编写和维护测试的客户端或服务器端实际需要,是否你创建一个新的应用程序或遗留代码重写的方法来减少代码复杂性单元测试、代码覆盖率,调试,和自动化,你会学习的整体方法编写代码,你和你的同事可以很容易...

    基于Vue+JavaScript的台式离心飞轮训练系统源码-单机版.zip

    基于Vue+JavaScript的台式离心飞轮训练系统源码-单机版.zip基于Vue+JavaScript的台式离心飞轮训练系统源码-单机版.zip基于Vue+JavaScript的台式离心飞轮训练系统源码-单机版.zip基于Vue+JavaScript的台式离心飞轮...

    PerfTests:JavaScript 继承性能测试正确完成

    2015 年 3 月 9 日更新:“Native Unwrapped”和 ClassManager“polymorphic”和“full ...创建微基准测试是一门艺术,它需要对浏览器内部结构的深入理解和一些人类的适应能力。 例如:混合类生成和方法调用的测试不

    基于JavaScript的著作权信息登记系统源码.zip

    该项目是个人毕设项目,答辩评审分达到95分,代码都经过调试测试,确保可以运行!欢迎下载使用,可用于小白学习、进阶。 该资源主要针对计算机、通信、自动化等相关专业的学生、老师或从业者下载使用,亦可作为期末...

    基于原生HTML+CSS+JavaScript实现的恋爱网页源码.zip

    该项目是个人毕设/课设/大作业项目,代码都经过本地调试测试,功能ok才上传,高分作品,可快速上手运行!欢迎下载使用,可用于小白学习、进阶。 该资源主要针对计算机、通信、人工智能、自动化等相关专业的学生、...

    基于JavaScript的航智体检管理系统源码(软件工程课设).zip

    基于JavaScript的航智体检管理系统源码(软件工程课设).zip基于JavaScript的航智体检管理系统源码(软件工程课设).zip基于JavaScript的航智体检管理系统源码(软件工程课设).zip基于JavaScript的航智体检管理系统源码...

Global site tag (gtag.js) - Google Analytics