Y.Lang.isUndefined vs typeof undefined,哪个更好,为什么? [英] Y.Lang.isUndefined vs typeof undefined, which is better and why?

查看:12
本文介绍了Y.Lang.isUndefined vs typeof undefined,哪个更好,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道为什么 YUI 库使用 Y.Lang.isUndefined() 即使 JS 有一个内置功能来检查变量的类型.

I was wondering why YUI libs use Y.Lang.isUndefined() even when JS has a built in feature to check type of a variable.

推荐答案

该方法存在的原因是为了 API 一致性——YUI 团队认为将它排除在外会很奇怪.正如 LightStyle 指出的那样,isUndefined() 没有做任何特别的事情,所以除非你真的很喜欢它的美感,否则你可能不应该使用它.

The reason that method exists is for API consistency -- the YUI team felt it would be weird to leave it out. As LightStyle points out, isUndefined() doesn't do anything special, so you probably shouldn't use it unless you really like the aesthetics.

事实上,只有少数 YUI 类型检查方法可以完成您在本机无法完成的任何实际有用的工作.Ryan Grove 在他的演讲 何时不使用 YUI (youtube.com)

In fact, only a few of the YUI type checking methods do any actual useful work beyond what you could do natively. Ryan Grove has a detailed walkthrough of these methods (and why you should avoid most of them) in his talk, When Not To Use YUI (youtube.com)

这篇关于Y.Lang.isUndefined vs typeof undefined,哪个更好,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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