简单的vanilla JavaScript比使用jQuery或MooTools这样的框架更好吗? [英] Is plain vanilla JavaScript better than using frameworks like jQuery or MooTools?

查看:62
本文介绍了简单的vanilla JavaScript比使用jQuery或MooTools这样的框架更好吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道依赖jQuery或 MooTools 等框架是不是一个好主意,或者我们应该只使用普通的JavaScript吗?

I am wondering if it is a good idea to rely on frameworks like jQuery or MooTools or should we just use plain JavaScript?

除了避免重新发明轮子外,他们是否添加了任何具体值?

Apart from avoiding the re-invention of wheel, do they add any specific value?

由于框架对公众开放,是否有可能利用框架中可能出现的任何安全漏洞(当然,无意中:))?

Since the frameworks are open to the public, can there be possibility of exploitation of any security holes that might appear (of course, unintentionally :) ) in the frameworks?

在选择框架或其他方面是否还有其他要点?

Are there any other points that are to be considered when choosing a framework or otherwise?

推荐答案


  1. 框架解决了跨浏览器的错误,通常需要花费数小时的时间,因此您可以专注于功能而不必担心某些边缘案例浏览器错误...而不是浪费4-5个小时来解决错误花费的时间和你的家人在一起。

  1. Frameworks solve cross-browser bugs which normally would cost hours of your time, so you can focus on functionality instead of worrying about some edge case browser bug.. instead of wasting 4-5 hours solving a bug spend that time with your family.

像jQuery这样的框架很像装载像animati这样的东西on,selectors,html操作因此通常会在库中内置某种功能,再次为您节省更多时间,API使实际完成复杂事情变得非常容易。

Frameworks such as jQuery are pretty loaded with stuff like animation, selectors, html manipulation so there's usually some sort of functionality already built into the library, again saving you more time and the API makes it really easy to actually accomplish complex things.

口译员和浏览器变得越来越快,所以我并不特别认为加载整个库是一个很大的问题。此外,多亏了Google等人,我们得到了非常快的cdns,现在很多网站都使用相同的URI来拉入脚本,这意味着脚本在另一个网站上被缓存和重用的速率更高。

Interpreters and browsers are only getting faster and faster so I don't particularly think it's a huge issue loading an entire library up. In addition thanks to Google et al we get very fast cdns and nowadays lots of sites are using the same exact URI to pull the script in, meaning there's a higher rate of the script getting cached and reused on another site.

而不是每个网络开发人员都拥有自己的库,而是让成千上万的人集中精力改善少数几个库,以便更好地记录跨浏览器的错误并修复。

Instead of every single web developer having their own library it's much more efficient having thousands of people concentrated to bettering a handful of libraries so cross-browser bugs get documented and fixed.

竞争是一件好事,光滑测试的结果导致了更快的选择器引擎,如Sizzle。开发人员不必担心琐碎的DOM错误意味着每天都会创建更复杂的库,这意味着入门级开发人员可以访问非常强大的插件。

Competition is a good thing, the result of the slickspeed tests resulted in much faster selector engines such as Sizzle. Developers not having to worry about trivial DOM bugs means more complex libraries are created daily, which means entry-level developers have access to very powerful plugins.

就安全性而言,例如jQuery将检测浏览器是否能够本机解析JSON,如果是,依赖于此。通常任何现代浏览器都会有这个,它比 eval 更安全...所以jQuery首先努力使用更安全,更安全的方法。如果没有可用的JSON.parse方法,它将使用eval。

As far as security, jQuery for example will detect if the browser is capable of parsing JSON natively and if so, rely on that. Usually any modern browser will have this, and it's much safer than eval... so jQuery strives to use the safer and more secure methods first. It will only use eval if there isnt a JSON.parse method available.

在jQuery中要记住的一件重要事情是记住你是仍在Javascript中编码。通常人们会过多地接受糖衣方法并将所有包裹在 $ 中,我认为知道你仍然可以做 this.href 而不是 $(this).attr('href')如果你想要一个绝对标准化的uri,例如。

An important thing to remember in jQuery though is remembering you're still coding in Javascript. Usually people get too caught up in the sugar coated methods and wrapping everything in $, I think it's important to know you can still do this.href instead of $(this).attr('href') if you would like an absolutely normalized uri for example.

这篇关于简单的vanilla JavaScript比使用jQuery或MooTools这样的框架更好吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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