本文介绍了理解JavaScript - 资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用StackOverflow的微小Diggit / Blog功能描述:

Using the tiny Diggit/Blog feature of StackOverflow described here:

我想发布以下谷歌技术讲座视频,我发现它非常有趣。

I would like to post the following Google tech talk video I have just saw and that I found quite interesting.

我一直有理解javascript自然的问题。

I have always had problems understanding javascript "nature".

这里,由Douglas Crockford描述

Here, the JavaScript good parts are described by Douglas Crockford

我希望你发现这个链接很有用。

I hope you find this link useful.

现在问题部分:

您对javascript的抱怨是什么?
您是否使用IDE进行javascript编辑?
你认为这个视频有助于理解好的部分吗?

What are your complaints about javascript?Do you use an IDE for javascript editting? Do you think this video helps to understand the "good parts"?

推荐答案

JavaScript:坏的部分。

JavaScript: the bad parts.


  1. 最大的错误是后期错误检测。 JavaScript很乐意让你访问一个不存在的对象成员,或者将错误数量的参数传递给一个函数,并用'undefined'对象填补空白,除非你刻意检查它们(这对于继续在各处做是不切实际的) ),将导致异常或稍后生成意外值。可能很久以后,导致在实际问题代码附近出现的细微且难以调试的错误。这些条件应该生成异常,除了JS最初没有引发异常。 'undefined'是一个快速而又肮脏的黑客,我们现在已经陷入困境。

  1. The biggest mistake is late error detection. JavaScript will happily let you access a non-existant object member, or pass the wrong number of arguments to a function, and fill the gap with ‘undefined’ objects, which, unless you deliberately check for them (which is impractical to keep doing everywhere), will cause an exception or generate an unexpected value later on. Possibly much later on, resulting in subtle and difficult-to-debug errors appearing nowhere near the actual problem code. These conditions should have generated exceptions, except that JS didn't originally have exceptions to raise. ‘undefined’ was a quick and dirty hack we're now stuck with.

未声明的变量默认为全局范围。这几乎不是你想要的,当两个函数都忘记'var'并且开始使用相同的全局时,会导致细微且难以调试的错误。

Undeclared variables defaulting to global scope. This is almost never what you want and can cause subtle and difficult-to-debug errors when two functions both forget ‘var’ and start diddling the same global.

即使对于基于原型的OO语言,构造函数的模型也很奇怪,甚至使有经验的用户感到困惑。忘记'new'会导致细微且难以调试的错误。虽然你可以从中创建一个可通过的类/实例系统,但是没有标准,并且人们仍在使用的早期教程中提出的大多数类系统都非常不合适,并且混淆了JavaScript实际上是在做。

The model of constructor functions is weird even for a prototype-based-OO language and confuses even experienced users. Forgetting ‘new’ can result in subtle and difficult-to-debug errors. Whilst you can make a passable class/instance system out of it, there's no standard, and most of the class systems proposed in the early tutorials that people are still using are both desperately inadequate, and obfuscate what JavaScript is actually doing.

缺少绑定方法。在调用它时访问object.method与'this'中的'object'进行魔术连接完全不直观,但是传递object.method作为引用会失去连接;没有其他语言这样工作。当发生这种情况时,'this'被设置为一个意外的值,但它不是'undefined'或其他会引发异常的东西。相反,所有属性访问都在窗口结束,稍后会导致细微且难以调试的错误。

Lack of bound methods. It's utterly unintuitive that accessing "object.method" when calling it makes a magic connection to ‘object’ in ‘this’, but passing "object.method" as a reference loses the connection; no other language works this way. When this happens, ‘this’ is set to an unexpected value, but it's not ‘undefined’ or something else that would raise an exception. Instead, all the property access ends up on ‘window’, causing subtle and difficult-to-debug errors later.

没有整数类型。数字看起来像一个但以各种方式分解(例如,n + 1 == n足够高的n)。任何时候NaN或Infinity都会潜入(如果您认为自己正在处理整数,则非常意外),您将无法立即发现;相反,将会出现细微且难以调试的错误。

There is no integer type. Number looks like one but breaks down in various ways (eg. n+1==n for high enough n). Any time a NaN or Infinity sneaks in (quite unexpectedly if you think you are dealing with integers) you won't find out immediately; instead there will be subtle and difficult-to-debug errors down the line.

没有关联数组类型。对象看起来像一个,但在各种意外的键下分解。数组不是纯列表。任何时候你使用'for ... in',你可能陷入陷阱,并且会经历......是的,微妙且难以调试的错误。

There is no associative array type. Object looks like one but breaks down under various unexpected keys. Arrays aren't pure lists. Any time you ever use ‘for...in’, you have probably fallen into a trap, and will experience... yes, subtle and difficult-to-debug errors.

一般来说,对于脚本语言来说,字符串处理很差。 String.split(,limit)和String.replace()没有做你想象的事情,导致......你知道。 toString()的结果通常很差,对调试没有用。与此同时,我们遇到了一堆垃圾Netscape认为可能有用,比如String.prototype.blink(),以及永久损坏的escape()。是的。

Generally poor string handling, for a scripting language at least. String.split(, limit) and String.replace() don't do what you might think, causing... you know. The results of toString() are generally poor and not useful for debugging. Meanwhile we are stuck with a load of rubbish Netscape thought might be useful, like String.prototype.blink(), and the perpetually broken escape(). Yay.

然后然后存在所有浏览器差异(IE仍然缺少基本对象上的许多基本方法),和... ...

And then there's all the browser differences (IE is still missing a lot of essential methods on the basic objects), and the DOM...

最后,即使发生异常,也会隐藏起来远离视图,因此作者甚至都不会意识到是错的。结果是大多数网站都充满了错误;在IE中启用完整的JavaScript错误报告,结果无法使用。

And finally, even when an exception does occur, it is hidden away from view, so the author won't even realise something is wrong. The result is that most sites are chock full of errors; turn on full JavaScript error reporting in IE and the result is unusable.

让我觉得新一代程序员正在学习这种作为第一语言的东西。更糟糕的是,他们正在学习的大部分教程材料(我的文章AEWsome R0LL0VERZ!)总是鼓励最糟糕的做法。 'javascript:'URL,'eval()'用于所有内容,特定于浏览器的DOM访问... oy。

It scares me to think a new generation of programmers are learning this tosh as a first language. What's worse, most of the tutorial material they're learning from ("My fiRST AEWsome R0LL0VERZ!") invariably encourages the worst possible practice. ‘javascript:’ URLs, ‘eval()’ for everything, browser-specific DOM access... oy.

这篇关于理解JavaScript - 资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 12:27