


Summarize and share some jQuery-based front-end interviews (including mobile terminal FAQs)
This article summarizes some front-end interviews based on jQuery to share with you. It contains common interview questions about jQuery and common mobile questions. I hope it will be helpful to everyone!
Related recommendations: 2022 Big Front-End Interview Questions Summary (Collection)
jQuery front-end interview - including mobile terminal FAQ
1. Have you seen the source code of JQuery? Can you give a brief overview of its implementation principle?
jquery source code is encapsulated in a self-execution environment of an anonymous function, which helps to prevent global pollution of variables. Then by passing in the window object parameters, the window object can be used as a local variable. , the advantage is that when accessing the window object in jquery, there is no need to return the scope chain to the top-level scope, so that the window object can be accessed faster. Similarly, passing in the undefined parameter can shorten the scope chain when looking for undefined. [Recommended learning: jQuery video tutorial]
(function( window, undefined ) { //用一个函数域包起来,就是所谓的沙箱 //在这里边var定义的变量,属于这个函数域内的局部变量,避免污染全局 //把当前沙箱需要的外部变量通过函数参数引入进来 //只要保证参数对内提供的接口的一致性,你还可以随意替换传进来的这个参数 window.jQuery = window.$ = jQuery; })( window );
- jquery encapsulates some prototype properties and methods in jquery.prototype. In order to shorten the name, it is assigned to jquery.fn, this is a very vivid way of writing.
- There are some array or object methods that are often used. jQuery saves them as local variables to improve access speed.
- The chain call implemented by jquery can save code, and the same object is returned, which can improve code efficiency.
- The advantage of jquery is chain operations and implicit iteration
2. What object does this return from the init method of jQuery.fn refer to? Why return this?
The returned this refers to the jquery object after the current operation. In order to realize the chain operation of jquery
3. How to use jquery Convert array to json string and then back again?
Use jquery global method $.parseJSON this method
4. What is the implementation principle of jQuery’s attribute copy (extend) and how to implement it Deep copy?
①、$.extend shallow copy in jQuery
$.extend shallow copy in jQuery, when copying object A, object B will copy all fields of A , if the field is a memory address, B will copy the address, if the field is a primitive type, B will copy its value. Its disadvantage is that if you change the memory address pointed by object B, you also change the field of object A pointing to this address.
$.extend(a,b)
②、$.extend deep copy in jQuery
$.extend deep copy in jQuery. This method will completely copy all the data. The advantage is B There is no mutual dependence on A (A and B are completely disconnected). The disadvantage is that the copy speed is slower and the cost is higher.
$.extend(true,a,b)
5. What is the difference between jquery.extend and jquery.fn.extend?
①, jQuery.extend(object);
- It is to add a class method to the jQuery class, which can be understood as adding a static method. For example:
jQuery.extend({ min: function(a, b) { return a < b ? a : b; }, max: function(a, b) { return a > b ? a : b; }); jQuery.min(2,3); // 2 jQuery.max(4,5); // 5
-
jQuery.extend(target, object1, [objectN])
Extend an object with one or more other objects and return the extended object .
var settings = { validate: false, limit: 5, name: "foo" }; var options = { validate: true, name: "bar" }; jQuery.extend(settings, options);
- Result: settings == { validate: true, limit: 5, name: “bar” }
②、jQuery.fn.extend( object);
- #$.fn?
- $.fn refers to the namespace of jQuery. The members on fn (method function and attribute property) will affect the jQuery instance Every one works.
- Looking at the jQuery code, it is not difficult to find.
jQuery.fn = jQuery.prototype = { init: function( selector, context ) {//.... };
- Original
jQuery.fn = jQuery.prototype
- So, it is an extension of jQuery.prototype, which is to add " member function". Instances of the jQuery class can use this "member function".
③、Difference
- jQuery.fn.extend(object); extends jQuery object method
- jQuery.extend extends jQuery global method
6. How is jQuery’s queue implemented? Where can queues be used?
In the core of jQuery, there is a set of queue control methods. This set of methods consists of three methods: queue()/dequeue()/clearQueue(). It needs to be executed continuously and sequentially. The control of the function can be said to be concise and comfortable. It is mainly used in the animate () method, ajax and other events that need to be executed in chronological order.
var _slideFun = [ function() { $('.one').delay(500).animate({ top: '+=270px' },500, _takeOne); }, function() { $('.two').delay(300).animate({ top: '+=270px' },500, _takeOne); } ]; $('#demo').queue('slideList', _slideFun); var _takeOne = function() { $('#demo').dequeue('slideList'); }; _takeOne();
7. Let’s talk about the functions in Jquery What are the differences between bind(), live(), delegate() and on()?
bind(), live(), and delegate() in jquery are all implemented based on on
Method | Description |
---|---|
##on
| encapsulates a compatible event binding method that binds one or more events to the event processing function on the selected element |
bind(type,[ data],fn)
| Bind event handlers for specific events of each matching element|
live(type,[data], fn)
| Append an event handler to all matching elements, even if the element is added later|
delegate(selector, [type],[data],fn)
| Add one or more event handlers to the specified element (a child element of the selected element) and specify the function to run when these events occur
.bind() is directly bound to the element
Description | |
---|---|
.bind()
| is directly bound Set on the element |
.live()
| is bound to the element through bubbling. More suitable for list types, bound to document DOM nodes. The advantage of .bind() is that it supports dynamic data|
.delegate()
| is a more accurate small-scale use of event agents. The performance is better than .live()|
.on()
| is the latest version 1.9 that integrates the previous three methods. Event binding mechanism
方法 | 说明 |
---|---|
.get |
是jquery中将jquery对象转换为原生对象的方法 |
[] |
是采用了获取数组值的方式将jquery对象转换为原生对象的方法 |
eq() |
是获取对象列表中的某一个jquery dom对象 |
18、请指出$ 和$.fn 的区别,或者说出$.fn 的用途。
$代表的是jquery对象
$.fn是代表的jQuery.prototype
$.fn是用来给jquery对象扩展方法的
19、jQuery取到的元素和原生Js取到的元素有什么区别
jQuery取到的元素是包含原生dom对象,和jQuery扩展的方法
20、原生JS的window.onload与Jquery的$(document).ready(function(){})有什么不同?如何用原生JS实现Jq的ready方法?
①、window.onload()
window.onload()方法是必须等到页面内包括图片的所有元素加载完毕后才能执行。
②、$(document).ready()
$(document).ready()是DOM结构绘制完毕后就执行,不必等到加载完毕。
function ready(fn){ if(document.addEventListener) { //标准浏览器 document.addEventListener('DOMContentLoaded', function() { //注销事件, 避免反复触发 document.removeEventListener('DOMContentLoaded',arguments.callee, false); fn(); //执行函数 }, false); }else if(document.attachEvent) { //IE document.attachEvent('onreadystatechange', function() { if(document.readyState == 'complete') { document.detachEvent('onreadystatechange', arguments.callee); fn(); //函数执行 } }); } };
(学习视频分享:web前端教程)
The above is the detailed content of Summarize and share some jQuery-based front-end interviews (including mobile terminal FAQs). For more information, please follow other related articles on the PHP Chinese website!

Yes, the engine core of JavaScript is written in C. 1) The C language provides efficient performance and underlying control, which is suitable for the development of JavaScript engine. 2) Taking the V8 engine as an example, its core is written in C, combining the efficiency and object-oriented characteristics of C. 3) The working principle of the JavaScript engine includes parsing, compiling and execution, and the C language plays a key role in these processes.

JavaScript is at the heart of modern websites because it enhances the interactivity and dynamicity of web pages. 1) It allows to change content without refreshing the page, 2) manipulate web pages through DOMAPI, 3) support complex interactive effects such as animation and drag-and-drop, 4) optimize performance and best practices to improve user experience.

C and JavaScript achieve interoperability through WebAssembly. 1) C code is compiled into WebAssembly module and introduced into JavaScript environment to enhance computing power. 2) In game development, C handles physics engines and graphics rendering, and JavaScript is responsible for game logic and user interface.

JavaScript is widely used in websites, mobile applications, desktop applications and server-side programming. 1) In website development, JavaScript operates DOM together with HTML and CSS to achieve dynamic effects and supports frameworks such as jQuery and React. 2) Through ReactNative and Ionic, JavaScript is used to develop cross-platform mobile applications. 3) The Electron framework enables JavaScript to build desktop applications. 4) Node.js allows JavaScript to run on the server side and supports high concurrent requests.

Python is more suitable for data science and automation, while JavaScript is more suitable for front-end and full-stack development. 1. Python performs well in data science and machine learning, using libraries such as NumPy and Pandas for data processing and modeling. 2. Python is concise and efficient in automation and scripting. 3. JavaScript is indispensable in front-end development and is used to build dynamic web pages and single-page applications. 4. JavaScript plays a role in back-end development through Node.js and supports full-stack development.

C and C play a vital role in the JavaScript engine, mainly used to implement interpreters and JIT compilers. 1) C is used to parse JavaScript source code and generate an abstract syntax tree. 2) C is responsible for generating and executing bytecode. 3) C implements the JIT compiler, optimizes and compiles hot-spot code at runtime, and significantly improves the execution efficiency of JavaScript.

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Atom editor mac version download
The most popular open source editor

WebStorm Mac version
Useful JavaScript development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function
