Home  >  Article  >  Web Front-end  >  Summary of Jquery's flaws_jquery

Summary of Jquery's flaws_jquery

WBOY
WBOYOriginal
2016-05-16 18:10:291056browse

Yes, jquery has successfully explored selector, chain usage, gsetter usage, many simplified naming, etc., making the front end easy and simple, making a huge contribution to web development.
However, it also has some unsatisfactory aspects.

1. About one of the code lumps.

I have always felt that jquery is a product of personal heroism. The number of people who have the patience to read his code is definitely less than 1%.
After sizzle became independent, ms has undergone some changes.
But the styles that are different and related to each other are still everywhere in sizzle and jquery.
Sometimes I think: If John stopped writing code, who would be willing to take over these messes.

2. About Code Tuo No. 2.

I wonder if any component developers have ever thought about "relying on jquery to develop a component that can run independently without relying on jquery"?
Is this a strange requirement? ----It seems not.
Is there such a need? ----Many students will say: "JQuery has deep roots and can be relied on, so why should it run independently?"
Also, the level of component developers is generally pretty good, and they will find ways to solve these problems. . If there is such a need, they will find the corresponding method library.
However, this also shows that jquery cannot meet the needs of these people.
Because jquery is just a mess of code. It is almost impossible to split it into a static method library.

3. About the "focus on dom" one.

I don’t know whether to say yes or not.
I feel that jQuery’s team is definitely capable of building a comprehensive framework, rather than just “focusing on DOM”.
When using jquery and jquery components, we may have to find a seed file ourselves for asynchronous loading, etc.
Because these seed requirements are actually not closely related to the dom, so jquery can completely ignore it-----it is very lazy.
Also, regarding torrent files, YUI3’s use as the core point is a good idea, but it’s a pity that it goes too far. After arriving at YUI3, I wanted to use only its selector for performance comparison, but I had to load a push file to do it.

4. Regarding "focus on dom" part two.
“jquery focuses on dom”,
Does the string trim need to be in jquery? ----It seems unnecessary. But jquery provides it conveniently. Similar ones include parseJSON, globalEval, etc.
What about the string template function (tmpl)? ----The template should obviously be based on strings, because string templates are often used to organize html characters, so jquery will forcefully put them in. And it is based on DOM. ----I really want to say: It’s really far-fetched.
In our projects, we may also use many string-related functions (trim|subByte|encode4Hhtml, etc.), object-related functions (get|dump|mix, etc.), and array-related functions (forEach |map), etc.
Jquery has no intention of helping us solve these problems, so do we have to ask someone else to solve them or solve them ourselves?

5. About sizzle.
A: Sometimes I feel that sizzle is a semi-finished product, and some functions that could have been easily provided are not provided.
For example:
selector2filter(selector) //Convert a selector into a filter function.
filter(els,selector,refEl) //Use ref as the reference element and filter els according to the selector condition. For example, it is used when delegating. Since sizzle is not provided, the reference element of '>li' in $('#id').delegate('>li','click',handle) is not the object corresponding to #id
B: sizzle If you want to solve the following two problems, you may have to break your muscles.

Copy code The code is as follows:

theme< ;/h1>
  • Detail 1.1
  • Detail 1.2

  • Detail 2.1
  • Details 2.2

<script> <br>alert($('#head1~ul>li').length);/ / should be 4 not 0. Because sizzle was lazy when selecting the candidate set and did not deal with the candidate set problem seriously <br></script>


Copy code The code is as follows:












<script> <br>alert($ ('li>divspan').length); 왜냐하면 sizzle은 필터링 중에 게으르고 역추적을 무시했기 때문입니다. <br></script>


C: 조금 생각해보면 Sizzle에는 코드가 많습니다. YUI 이후 무려 13K가 나오고, 그가 추가한 몇 가지 약어를 제외하면 여전히 11K가 넘습니다.

6. . . .
피곤해서 나중에 얘기하자.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:The difference between quick sorting php and javascript_javascript skillsNext article:The difference between quick sorting php and javascript_javascript skills

Related articles

See more