@摘要:
1.介绍了JavaScript的诞生历史和发展过程。
2.谈论当前的Web Tech情况。比如纯的HTML5已经足够优秀,当然V8解释器对JS来说又是性能的一大飞跃。
3.作者谈到好多人只知道JQuery而不知道JavaScript ,哈哈哈。认为JQery才是一门语言,但是JS’s作者没谈关于NodeJS,哈哈哈。
3.John Resig谈了Jquery这个工具库的诞生。以及它的设计哲学,完美的文档,完美的社区,完美的迭代。
仅仅标注部分专业释义的词汇,避免通俗释义
I was hired at(供职于)Netscape in April, 1995. Netscape had already launched(上线发布) its 1.0 Mosaic killer. If you remember, Mosaic was the big, I would say Mosaic was the big browser until Netscape took over, so when I came to Netscape, they’d been going for about a year. I actually had an option to go on to it at the beginning and I passed it up, but I went in in time to do what I was tempted(被吸引) to do, which is a programming language for HTML for web designers and programmers to use embedded(嵌入式) directly in the web page. Not something that was like coming along at the time called Java which was more of a professional’s(专业的) language where you would write real code with type declarations and you would have to write that code in a way that compiled(编译的). I was writing something, JavaScript, that could be used by people who didn’t know what a compiler(编译器) was. They were just going to load it, it was like BASIC. And that was really the pitch, that we would make two languages, not one, analogous(类似的) to Microsoft’s Visual Basic for C++, so JavaScript for Java. Bill Joy of Sun actually liked that idea, and agreed with it. And he was the guy that signed the trademark(商标) license(许可证), by which what I had created became JavaScript. The name is a total lie, it’s not really related(有亲属关系) to Java so much as to a common ancestor(祖先) C in syntax. And, and, to the extent(程度) that we made it easy to use and something you could copy, paste, program, or start small from scripts and grow to programs, JavaScript has succeeded massively(巨大的). It was also an incredible(难以置信) rush job, so there were mistakes in it. And something that I think is important about it is that it, I knew there would be mistakes and there would be gaps, so I made it very malleable(可塑) as a language. And that has enabled(使得…能够) web developers to make it be what they want it to be, to project their own style of, not just API but almost language pattern on it and create their own innovation(创新的) networks, to use Eric von Hippel’s phrase, or innovation toolkits on top of it. So it’s not a language that tries to restrict(约束) you to one paradigm(范例), it’s a multi-paradigm(多个范例) language. >> I mean, there’s all these things where a language comes out and immediately trips and falls and you have to sort of, it’s okay >> Mm-hm. >> the second time, >> Mm-hm. >> But there wasn’t really a trip and fall in JavaScript, why? >> So you could say there hasn’t been a version two and that’s true because I’ve tried to work on what might be a big version two, that was called the fourth edition, and that failed.
There has been evolution(不断演化). The web is all about evolution. People don’t quite see this while you’re in the midst of it because it’s microevolution(micro微小演化). But web pages from the 90s don’t all render properly these days, they don’t all work right. And a lot of them are lost, and only available through webarchive.org. JavaScript had enough at the beginning, enough good parts to use Crockford’s phrase(语法), or enough genetic material (遗传的元素)from other languages. You know, first-class functions, prototypal inheritance(继承) from self. The inheritance of first-class functions from Scheme is really kind of a fraud because Scheme is different in many ways and I couldn’t make those differences manifest. I couldn’t do the Scheme thing in JavaScript. That was under these marching orders to make it look like Java. I had ten days to prototype it. So Scheme was more of a spiritual than a actual influence. But first-class functions are very powerful and they fit with an event handling sort of programming model. I was inspired by Atkinson’s Hypercard. So that’s why you see onClick in Javascript. Hypercard had this pattern for event handlers called on, you know, onPage, the downer, whatever.
So JavaScript had enough good at the beginning to survive. Now if you think back though to the mid 90s, Javascript was cursed(被诅咒) because it was mainly used for annoyances like little scrolling messages in the status bar(状态栏) at the bottom of your browser or flashing images or things that popped up windows massively. We could have put in controls for those, and we should have. Eventually, browsers Firefox kind of championed this, led this automatic suppression of annoyances that made it all much better. And with Moore’s Law compounding and with JavaScript getting some evolutionary improvements in the standards process, it became really quite fast enough and good enough in 2004 and 5, to beget the Web 2.0 revolution. That was, I think, tied in with Firefox’s retaking market share from IE and developers realizing there was a client side to the programming stack that could be expressive and powerful, and could be fast enough thanks to faster computers mainly. >> You must have had some kind of training. >> Oh, I’d done a lot of >> Some kind of set of experiences that got to the point where you could pull from Scheme, and, and. >> Mm-hm. I had implemented, I was sort of a language buff when I first entered computer science. I was a math/physics major originally and ended up math and computer science when I finally got my undergraduate degree. So I, I was programming formal language theory applied to recognizing languages. Lexical analysis, parsers, automatically constructed parsers from grammars. I loved that stuff because it was all very pretty and clean, theoretically. And it, it still is. It hasn’t changed a lot. There’s been only one or two innovations since my time at the university in the early 80s. So what, what that gave me was the ability to quickly knock out, you know, sort of a, a language interpreter. I could do the parser and the scanner, I could generate bytecode, because Netscape wanted to do a server-side embedding, and JavaScript, even though it could have been a treewalk or something that interpreted parse trees, I made a bytecode for it. And it was an internal bytecode, not the Java bytecode that’s become a handicap for Java, I think. And I knocked all that out really quickly because I’d done it before. I’d done it at Silicon Graphics to build sort of network monitoring tools to capture packets based on expressions that were fields of the various protocol headers. I’d done it for fun, just to make my own languages. And finally I got to do it really quickly. The, the speed was an issue for me. It was partly we were all feeling like Microsoft was going to come after Netscape. Because they had tried to buy Netscape in late 94 for too little money. I’d heard about this, it was before my time at Netscape. But we also were in a weird game period with respect to Java. Because even at Netscape, some people thought, well, if we have Java, do we really need a second language? They didn’t see the benefit of the Visual Basic companion language for a much larger cohort of programmers or amateurs, designers, beginners. To, to write Java, as to write C++ for the Microsoft platform today, took a lot of education, greater pay. It was a higher-priced proposition. To get people gluing components together and designing pages and filling gaps using JavaScript as they did with BASIC and Visual Basic and Microsoft’s Windows, was cheaper and wider spread. It also enabled this user innovation toolkit approach, to use Von Hippel’s phrase again. Because JavaScript was malleable, because there were so many web designers, you would see different schools of thought on how to use it emerge, and this has become quite clear over the past ten years with the various JavaScript libraries. And I think that’s actually an advantage, as I said earlier, to JavaScript, that we’re not telling you, here’s the one way to write it, here’s the one true object-oriented paradigm. Here’s the only way you should ever make a reusable extraction. It’s not unmixed, right? It’s hard for beginners, people reinvent certain wheels and make mistakes doing it, or don’t like having to acquire a library. But you see jQuery, a very popular library, because it gives people this very sweet query and do paradigm. And, and again it’s not mandatory with JavaScript, but a lot of people learn that and they think that it is Javascript. They think jQuery is a language, or they think, you know, jQuery is the tail that wagged the dog. jQuery is great, and Don Resnick used to work with us at Mozilla. And, but there are so many good libraries out there now. They’re actually shrinking and becoming more compositional, which is a good trend. So JavaScript, by being malleable and sort of fostering user innovation, I think has played a unique role. If I had done something more rigid, I think the odds are pretty good it would’ve failed. >> I, I just can’t imagine how you would have escaped from the object-oriented pattern of C++. >> Partly I had to, because if I’d done classes in JavaScript back in those ten days in May in 1995, I think I would have been told this is too much like Java, you’re competing with Java. You know, somebody at Sun would’ve yelled at Bill Joy more than they did. And it might have killed the deal. So I was definitely not only under a time constraint, but also under marching orders. Make it look like Java, but don’t make it too big for its britches. It’s just this sort of silly little brother language, right? A sidekick to Java. >> But then you, you put in some primitives. >> I snuck some stuff in, yeah. >> You put some primitives, you know, like closures and all those other things that, that is like you can build what you want. [LAUGH] >> Yes, and, and that kind of went under the radar for a lot of people, and it wasn’t all even there, you know, in good working order in the first release. But over the next few years it became not only well known, I would say more standardized than well known. Over the next ten years it became evangelized, like Crockford’s a big exponent of the closure pattern and the good uses you can make of closures. So people find the malleability and the expressiveness and the power compelling enough that some people actually resist any version two. They say, I don’t want you to add cliches or common, special forms for
patterns that I’m more happy writing myself or acquiring as a library myself. >> You, you’ve created an abstraction that implementers can do crazy things with, right? >> Mm-hm. >> And people can rethink what the interpreter’s really supposed to do. >> They can. >> And they can just say, okay, here comes V8. And it thought about a lot of things differently. >> And it puts, that’s right. >> Right. >> Optimizations that haven’t been tried, I would, I knew about these optimizations because I had studied Smalltalk itself. But nobody had gotten the time and the money. Google was maybe first. There were other efforts going on in parallel, and Apple and Mozilla have kept up as best they can. But V8 deserves a lot of credit for pushing this forward. It wasn’t quite as first on the scene as, as they claim, because it was all coming together in 2008. But it has been very helpful and it has shown people what can be done. What’s interesting to me is that you then go and put different, more intensive workloads on the language. And you see there’s a new V8 that should come out of somewhere. And it may not come out of Google because they may have tired of optimizing JavaScript. In fact I believe Dart is a response to that by the principals who did V8. They want to do a language where they don’t want have to worry about all this crazy compatibility.
It may not succeed and it also doesn’t give JavaScript the next level of performance. But I believe that level is there. And it’s still improving performance much more dramatically than a language like Java where the gains are a percent or a fraction of a percent on the standard benchmarks. But a lot of HTML5 development now, quote-unquote HTML5, JavaScript, CSS, web APIs, beyond what’s in HTML5, is taking off. You’re seeing like Zynga doing HTML5-only games. It’s really coming faster than some thought. And I talked to venture capitalist Fred Wilson of Union Square in New York he said yeah, it’s, it’s here. He thought it would take years. It’s, we’ve turned that corner. And so you call it HTML5, what it really means is it’s the web stack. It’s the same stack you use to write web pages and host the web apps. You can write apps that run in your device, apps that are maybe hosted maybe offline, and maybe the line is blurred so that you can associate them with a URL but you can also take them on the plane without any fear that you’re going to lose anything by disconnecting from the Internet.
看 我从2005年开始从事JQuery 在那之前 JQuery甚至还没有存在 它仅仅是我已经写完的一堆工具 主要因为我已经创建了很多网站以及 资源在那个时候 并且我一直想要利用这些 工具来简化我的开发过程 并且其中 之一 只是解决 像那个时候存在的浏览器兼容性问题 那个时候有Internet Explorer和Firefox 并且这是如此 难以尝试 比如同时针对这些不同的浏览器进行开发 那么这是一个问题 但是 另外一个问题是我觉得现存的开发工具 特别是JavaScript开发工具 可以变的更好
那个时候最流行的是名为prototype的JavaScript库 并且它是捆绑在Ruby on Rails框架里的 所以它的流行度被Rails带动了起来 并且那个库 实际上 我觉得是极其增长知识的 那是第一次我见到一个JavaScript库 以一种优雅 简洁的面向对象风格写成 你拥有优美的 所有这些优美的函数式在里面 并且我没有真正的意识到一个JavaScript库可以这么优美和优雅 并且一旦我见识到这个 这真的鼓舞了我去想要建造更好的东西 并且我意识到prototype主要集中注意力于JavaScript语言 但是没有太多的工具是关注于 在浏览器中的JavaScript语言 特别是操作HTML和DOM 所以这里有一个缺口并且 有这么大的一个可用性缺口 所以那个时候我就开始构建不同的工具和不同的库 并且最后所有这些黏在一起成为 一个单独的库 最后被叫做JQuery 我本来准备称它为JSelect 但是那个域名被注册了 诸如此类 所以最后使用了JQuery 并且 最后在2006年1月发布 我想说那个时候 我还在读大学 我在大学期间做了所有的这些事情 并且所有这些不同的项目和 我从事的这些东西仅仅是各式各样的边缘项目和我拥有的东西 JQuery就像从这些边缘项目中纺成的 实际上 那些边缘项目一个也没有留存下来 JQuery是仅存下来的一个 所以选择器模式来自于 至少我看到的 是来自英国的开发者Simon Willison所写的库 他创造了无论在哪儿 通过选择器获取元素的方法 如果我记的没错的话 它让你仅仅写一个简单的CSS选择器然后 找到一些元素 但是它非常的简单 你仅仅可以做最基础的查询 并且 它不支持完整的CSS2和CSS3以及其他东西
所以我想要做的事情之一是 其一 我想要一个比那个库更好的版本 一个更容易被理解的版本 另外 我想要实现将事件附加到页面中的这个过程 因为当你在构建一个交互式的JavaScript应用时 你需要监听用户做的一些事情的时机 所以做寻找一个元素并且 附加事件到该元素上这个过程 我想要完全优化这个过程 所以那真的是JQuery刚开始做的所有事情 后来没过多久我开始增加一些其他东西 像能够实现动画 甚至我是在发布它之后才把AJAX和其他东西加入了进去 那是因为其他人需要它 我甚至没有亲自用过它们 所以这真的是 我绝对是被其他这些开发者和 他们的库激发了并且他们的库不是十分的完美 我想要成为的仅仅是更加好一点的把所有东西组装在一起 那么 怎么说呢 就像你创造某个东西并且 让它依靠自己去发展 因为它靠自己去发展并没有花费多长时间
感觉上它好像花费了很长时间来靠自己发展 主要因为一些像 你知道的 2006年1月发布了它 我最开始做的一个设计决策之一 我想有不少 我一开始做的决策起到了很大的帮助 一个是我提供了一个明确的插件架构所以 大家可以写插件并且把它们放到JQuery库中 现在它们能够很好的利用这个框架 另一个我做的决策是在发布它的第一天 我写文档了 我坐下来并且每一个方法都过一遍 写文档描述方法如何工作的并且 提供小样例 让我觉得有趣的一件事是从 2006年1月我们发布这个库到2007年1月 JQuery是唯一的库 唯一写文档的JavaScript库 所有其他的差不多是 阅读源码或者去翻版本管理 或者不管它是什么 这真的是让我惊讶 好吧 我觉得这是开发者的一个副作用 你想要写你的代码 你不想做无聊的事情 写文档和其他的什么 然后 至少随着这个库的发展 有很多我做的决策在 它的历史中是不跟代码相关的 有一件事我总是强调 当你准备去 管理一个好的项目 特别是一个好的开源项目
代码仅仅是很小的一部分 你不得不花费很多时间和精力来做一些事情像
大家想要来学习 对他们来说容易学的东西 并且一旦他们学了 他们不会沮丧并且过些时候离开 有你掌握着整个流程 你不得不保证在路上的每一步 大家学习的时候是高兴和满足的 所以那通常涉及到做一些事情像你不得不保证 你有一个清楚的网站 下载任何你想要提供的东西是容易的 文档是非常清晰的 你有一个非常好的 开始向导 但是另外 你有一个围绕这个的社区 现在我带进JQuery团队的第一个人 目前是我 并且 下一个我带进的人 实际上是帮助管理社区的某个人 并且 不是另一个开发者 本质上 尽管他是个开发者 因为我想要这个的原因是 我想要保证如果任何人 在任何地方有问题 他们的需求会被考虑进来 并且我们能够帮助和解决他们遇到的任何问题 所以我们极其积极的解决浏览器的问题
寻找库里面的常见问题 从2006年夏天直到2006年底 我实际上在Y Combinator Paul Graham和Co办的创业公司加速器 那个时候 他们在波士顿 我和朋友们搬到了波士顿并且 我们准备开一个公司 最后失败了 我们没有拿到足够的融资并且它就是没有发展起来 创业公司解散后 我最后加入了Mozilla 我在那儿工作了很多年 作为一个JavaScript布道者 所以我的工作是推广JavaScript 帮助人们理解 规范 工具和所有其他一些类似的东西 但是又一次的 我实际上没有从事JQuery的工作 我还是会做那个 并且在我的业余时间我仅仅会 做邮件列表 解决错误和所有那些你不得不做的事情 直到我在Mozilla的最后一年 好像 好像差不多是2010年或者2011年 他们实际上说 好吧你可以从事JQuery全职工作 那是我开始从事它的时候 这是极好的 因为我最后在那个时候做的 是花费很多精力在保证基础设施的到位 所以如果我不从事它 如果我没有一天又一天的基础 它能够继续存在 部分原因是建立了一个非盈利组织和保证有足够的 人从事它的每一个方面 以至于当我最后来 加入可汗学院 我实际上从JQuery项目走了下来 并且自从那时起每一件事进行的非常好 并且我可以作为一个开心的JQuery使用者 [音乐]