Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
355 views
in Technique[技术] by (71.8m points)

javascript - 每个JavaScript程序员应该知道什么? [关闭](What should every JavaScript programmer know? [closed])

每个JavaScript程序员都应该知道一组能够说“我知道JavaScript”的东西吗?

  ask by community wiki translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Not jQuery.

(不是jQuery。)

Not YUI.

(不是YUI。)

Not (etc. etc.)

(不(等等))

Frameworks may be useful, but they are often hiding the sometimes-ugly details of how JavaScript and the DOM actually work from you.

(框架可能很有用,但它们经常隐藏有关JavaScript和DOM实际工作方式的丑陋细节。)

If your aim is to be able to say “I know JavaScript”, then investing a lot of time in a framework is opposed to that.

(如果您的目标是能够说“我知道JavaScript”,那么在框架中投入大量时间就与此相反。)

Here are some JavaScript language features that you should know to grok what it's doing and not get caught out, but which aren't immediately obvious to many people:

(这里有一些JavaScript语言功能,你应该知道它们正在做什么而不是被抓住,但对许多人来说并不是很明显:)

  • That object.prop and object['prop'] are the same thing (so can you please stop using eval , thanks);

    (object.propobject['prop']是一回事(所以请你停止使用eval ,谢谢);)

    that object properties are always strings (even for arrays);

    (对象属性总是字符串(即使对于数组);)

    what for ... in is for (and what it isn't ).

    (什么for ... in for (以及它不是 )。)

  • Property-sniffing;

    (物业嗅探;)

    what undefined is (and why it smells );

    (什么是undefined为什么它闻起来 );)

    why the seemingly-little-known in operator is beneficial and different from typeof / undefined checks;

    (为什么看似-鲜为人知的in操作者从有益的,不同typeof / undefined检查;)

    hasOwnProperty ;

    (hasOwnProperty ;)

    the purpose of delete .

    (delete的目的。)

  • That the Number datatype is really a float;

    (Number数据类型实际上是一个浮点数;)

    the language-independent difficulties of using floats;

    (使用花车的语言独立困难;)

    avoiding the parseInt octal trap.

    (避免使用parseInt八进制陷阱。)

  • Nested function scoping;

    (嵌套函数范围;)

    the necessity of using var in the scope you want to avoid accidental globals;

    (在你希望避免意外全局变量的范围内使用var的必要性;)

    how scopes can be used for closures;

    (范围如何用于闭包;)

    the closure loop problem .

    (闭环问题 。)

  • How global variables and window properties collide;

    (全局变量和window属性如何冲突;)

    how global variables and document elements shouldn't collide but do in IE;

    (全局变量和文档元素不应该如何冲突,而是在IE中发生冲突;)

    the necessity of using var in global scope too to avoid this.

    (在全局范围内使用var的必要性也是为了避免这种情况。)

  • How the function statement acts to ' hoist ' a definition before code preceding it;

    (function语句如何在前面的代码之前“ 提升 ”一个定义;)

    the difference between function statements and function expressions;

    (函数语句和函数表达式之间的区别;)

    why named function expressions should not be used .

    (为什么不应该使用命名函数表达式。)

  • How constructor functions, the prototype property and the new operator really work;

    (构造函数, prototype属性和new运算符的工作原理如何;)

    methods of exploiting this to create the normal class/subclass/instance system you actually wanted;

    (方法利用这个来创建普通的类/子类/实例,你其实是想系统;)

    when you might want to use closure-based objects instead of prototyping.

    (当你可能想要使用基于闭包的对象而不是原型时。)

    (Most JS tutorial material is absolutely terrible on this; it took me years to get it straight in my head.)

    ((大多数JS教程材料在这方面都非常糟糕;我花了很多年才把它直接放在脑海里。))

  • How this is determined at call-time, not bound;

    (如何this是在呼叫时间,而不是约束;)

    how consequently method-passing doesn't work like you expect from other languages;

    (因此,方法传递如何不像你期望的那样工作 ;)

    how closures or Function#bind may be used to get around that.

    (如何使用闭包或Function#bind来解决这个问题。)

  • Other ECMAScript Fifth Edition features like indexOf , forEach and the functional-programming methods on Array ;

    (其他ECMAScript第五版的功能如indexOfforEachArray的函数编程方法 ;)

    how to fix up older browsers to ensure you can use them;

    (如何修复旧浏览器以确保您可以使用它们;)

    using them with inline anonymous function expressions to get compact, readable code.

    (使用它们与内联匿名函数表达式来获得紧凑,可读的代码。)

  • The flow of control between the browser and user code;

    (浏览器和用户代码之间的控制流程;)

    synchronous and asynchronous execution;

    (同步和异步执行;)

    events that fire inside the flow of control (eg. focus) vs. events and timeouts that occur when control returns;

    (在控制流(例如焦点)内发生的事件与控制返回时发生的事件和超时;)

    how calling a supposedly-synchronous builtin like alert can end up causing potentially-disastrous re-entrancy.

    (如何调用像alert一样的同步内置可能最终导致潜在的灾难性重入。)

  • How cross-window scripting affects instanceof ;

    (跨窗口脚本如何影响instanceof ;)

    how cross-window scripting affects the control flow across different documents;

    (跨窗口脚本如何影响跨不同文档的控制流;)

    how postMessage will hopefully fix this.

    (postMessage将如何解决这个问题。)

See this answer regarding the last two items.

(有关最后两项,请参阅此答案 。)

Most of all, you should be viewing JavaScript critically, acknowledging that it is for historical reasons an imperfect language (even more than most languages), and avoiding its worst troublespots.

(最重要的是,你应该批判性地查看JavaScript,承认它是历史原因的一种不完美的语言(甚至超过大多数语言),并避免其最糟糕的麻烦。)

Crockford's work on this front is definitely worth reading (although I don't 100% agree with him on which the “Good Parts” are).

(克罗克福德在这方面的工作绝对值得一读(虽然我并不是100%同意他的“好零件”)。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...