我什么时候应该使用javascript框架库?

时间:2022-05-23 07:15:14

I'm writing a small web that just makes some animation and shows some information as a homepage and a list of links. All that is going to be generated dynamically in the client side. So everything is going to be javascript and XML.

我正在写一个小网站,只是做一些动画,并显示一些信息作为主页和链接列表。所有这些都将在客户端动态生成。所以一切都将是javascript和XML。

Recently I've been reading some questions in SO about javascript, and most of the situations involved the use and/or recommendation of a framework (jquery and friends). When a small web development should start considering the use of such a framework?

最近我一直在阅读有关javascript的SO中的一些问题,并且大多数情况涉及框架(jquery和朋友)的使用和/或推荐。当一个小的Web开发应该开始考虑使用这样的框架?

I've been until now doing my stuff just with plain javascript, as far as I'm not implementing a big site is it worth the learning a framework?

直到现在我只用普通的javascript做我的东西,只要我没有实现一个大网站是否值得学习框架?

Thanks

4 个解决方案

#1


On SO you will find a lot of people (including me) who advocate the use of jQuery (in particular). To me, it's everything a framework should be: small, lightweight, extensible, compact yet powerful and brief syntax and it solves some pretty major problems. I would honestly have a hard time trying to envision a project where I wouldn't use it (or another framework).

在SO上你会发现很多人(包括我)主张使用jQuery(特别是)。对我来说,这是框架应该是的一切:小巧,轻便,可扩展,紧凑但功能强大且语法简洁,它解决了一些非常重要的问题。老实说,我很难设想一个我不会使用它的项目(或其他框架)。

The reason to use it is to solve browser compatibility issues. Consider my answer to javascript to get paragraph of selected text in web page:

使用它的原因是解决浏览器兼容性问题。考虑我对javascript的回答,以获取网页中所选文本的段落:

function getSelectedParagraphText() {
  var userSelection;
  if (window.getSelection) {
      selection = window.getSelection();
  } else if (document.selection) {
      selection = document.selection.createRange();
  }
  var parent = selection.anchorNode;
  while (parent != null && parent.localName != "P") {
    parent = parent.parentNode;
  }
  if (parent == null) {
    return "";
  } else {
    return parent.innerText || parent.textContent;
  }
}

If you're familiar with Javascript a lot of this should be familiar to you: things like the check for innerText or textContent (Firefox 1.5) and so on. Pure Javascript is littered with things like this. Now consider the jQuery solution:

如果您熟悉Javascript,那么您应该熟悉很多内容:检查innerText或textContent(Firefox 1.5)等等。纯粹的Javascript充斥着这样的事情。现在考虑jQuery解决方案:

function getSelectedParagraphText() {
  var userSelection;
  if (window.getSelection) {
      selection = window.getSelection();
  } else if (document.selection) {
      selection = document.selection.createRange();
  }
  var parent = selection.anchorNode;
  var paras = $(parent).parents("p")
  return paras.length == 0 ? "" : paras.text();
}

Where jQuery really shines though is with AJAX. There JavaScript code snippets around to find the correct object to instantiate (XMLHttpRequest or equivalent) to do an AJAX request. jQuery takes care of all that for you.

尽管使用AJAX,jQuery真的很棒。有JavaScript代码片段可以找到要实例化的正确对象(XMLHttpRequest或等效的)来执行AJAX请求。 jQuery为您处理所有这些。

All of this for under 20k for the core jQuery Javascript file. To me, it's a must-have.

所有这一切都在20k以下的核心jQuery Javascript文件。对我来说,这是必须的。

#2


I'd start right now. Libraries like jQuery and prototype not only insulate you from browser differences, but also provide you with a shorthand for communicating your ideas to other programmers.

我现在就开始吧。像jQuery和prototype这样的库不仅可以使您免受浏览器差异的影响,还可以为您提供将您的想法传达给其他程序员的简写。

#3


Whenever writing javascript isn't your business.

每当写javascript不是你的业务。

JS libraries, other than providing helpers and shortcuts, also take care of corner cases, browser incompatibilities and quirks, and best practices. It is better that you spend time developing your application, and fall back to native JS only if you have to.

除了提供帮助和快捷方式之外,JS库还可以处理极端情况,浏览器不兼容性和怪癖以及最佳实践。您最好花时间开发应用程序,并且只有在必要时才回归本机JS。

#4


The deal with jquery is the approach to do javascript but with less work and communicate easier to others, so I would say Yes

与jquery的交易是做javascript的方法,但工作量少,沟通更容易,所以我会说是的

Think of it this way, would you rather write a paper in microsoft word or notepad

想一想,你宁愿用微软的单词或记事本写一篇论文

#1


On SO you will find a lot of people (including me) who advocate the use of jQuery (in particular). To me, it's everything a framework should be: small, lightweight, extensible, compact yet powerful and brief syntax and it solves some pretty major problems. I would honestly have a hard time trying to envision a project where I wouldn't use it (or another framework).

在SO上你会发现很多人(包括我)主张使用jQuery(特别是)。对我来说,这是框架应该是的一切:小巧,轻便,可扩展,紧凑但功能强大且语法简洁,它解决了一些非常重要的问题。老实说,我很难设想一个我不会使用它的项目(或其他框架)。

The reason to use it is to solve browser compatibility issues. Consider my answer to javascript to get paragraph of selected text in web page:

使用它的原因是解决浏览器兼容性问题。考虑我对javascript的回答,以获取网页中所选文本的段落:

function getSelectedParagraphText() {
  var userSelection;
  if (window.getSelection) {
      selection = window.getSelection();
  } else if (document.selection) {
      selection = document.selection.createRange();
  }
  var parent = selection.anchorNode;
  while (parent != null && parent.localName != "P") {
    parent = parent.parentNode;
  }
  if (parent == null) {
    return "";
  } else {
    return parent.innerText || parent.textContent;
  }
}

If you're familiar with Javascript a lot of this should be familiar to you: things like the check for innerText or textContent (Firefox 1.5) and so on. Pure Javascript is littered with things like this. Now consider the jQuery solution:

如果您熟悉Javascript,那么您应该熟悉很多内容:检查innerText或textContent(Firefox 1.5)等等。纯粹的Javascript充斥着这样的事情。现在考虑jQuery解决方案:

function getSelectedParagraphText() {
  var userSelection;
  if (window.getSelection) {
      selection = window.getSelection();
  } else if (document.selection) {
      selection = document.selection.createRange();
  }
  var parent = selection.anchorNode;
  var paras = $(parent).parents("p")
  return paras.length == 0 ? "" : paras.text();
}

Where jQuery really shines though is with AJAX. There JavaScript code snippets around to find the correct object to instantiate (XMLHttpRequest or equivalent) to do an AJAX request. jQuery takes care of all that for you.

尽管使用AJAX,jQuery真的很棒。有JavaScript代码片段可以找到要实例化的正确对象(XMLHttpRequest或等效的)来执行AJAX请求。 jQuery为您处理所有这些。

All of this for under 20k for the core jQuery Javascript file. To me, it's a must-have.

所有这一切都在20k以下的核心jQuery Javascript文件。对我来说,这是必须的。

#2


I'd start right now. Libraries like jQuery and prototype not only insulate you from browser differences, but also provide you with a shorthand for communicating your ideas to other programmers.

我现在就开始吧。像jQuery和prototype这样的库不仅可以使您免受浏览器差异的影响,还可以为您提供将您的想法传达给其他程序员的简写。

#3


Whenever writing javascript isn't your business.

每当写javascript不是你的业务。

JS libraries, other than providing helpers and shortcuts, also take care of corner cases, browser incompatibilities and quirks, and best practices. It is better that you spend time developing your application, and fall back to native JS only if you have to.

除了提供帮助和快捷方式之外,JS库还可以处理极端情况,浏览器不兼容性和怪癖以及最佳实践。您最好花时间开发应用程序,并且只有在必要时才回归本机JS。

#4


The deal with jquery is the approach to do javascript but with less work and communicate easier to others, so I would say Yes

与jquery的交易是做javascript的方法,但工作量少,沟通更容易,所以我会说是的

Think of it this way, would you rather write a paper in microsoft word or notepad

想一想,你宁愿用微软的单词或记事本写一篇论文