JavaScript
JavaScript prototype, prototype chain? What are the characteristics?
What does eval do?
Its function is to parse the corresponding string into JS code and run it;
You should avoid using eval, which is unsafe and very performance-consuming (twice, once to parse into a JS statement, and once to execute).
What is the difference between null and undefined?
Write a general event listener function.
// event (event) tool set, source: github.com/markyun
markyun.Event = {
using use using ’ through off out through out out through out out out out out out out out out out out out of to s t- ’ t- , (fn==null) {
fn=document; window.onload = fn, };
# // Use dom0||dom2||IE method to bind events depending on the ability
// Parameters: Operation element, event name, event handler
AddEvent: function(element, type, handler) {
use using use using ’ ’ s ’ using ’s ’ using ’s ’ out ’s through ‐ to ‐ ‐‐ ‐ ‐ to be captured, etc. ## {
element. element['on' type] = handler;
}
},
// 移除事件
removeEvent : function(element, type, handler) {
if (element.removeEnentListener) {
element.removeEnentListener( type, handler, false);
} else if (element.datachEvent) element.detachEvent('on' type, handler);
} else {
element. = null;
}
},
// Prevent events (mainly event bubbling, because IE does not support event capture)
stopPropagation: function(ev) {
if (ev.stopPropagation) {
ev.stopPropagation( ;
if (event.preventDefault) {
event.preventDefault(); //Get event target
getTarget : function(event) {
getEvent : function(e) {
var ev = e || window.event;
if (!ev) {
var c = this.getEvent.caller;
while (c) {
EV = C.ARGUMENTS [0];
If (EV && Event == EVSTRUCTOR) {
Break;
}
c = c.caller;
}
return ev;
High concurrency, chat, real-time message push
Introducing the basic data types of js.
number,string,boolean,object,undefined
How does Javascript implement inheritance?
Through prototypes and constructors
["1", "2", "3"].map(parseInt) What is the answer?
[1, NaN, NaN] Because parseInt requires two parameters (val, radix) but map passes 3 (element, index, array)
How to create an object? (Draw the memory map of this object)
function Person(name, age) {
this.name = name;
this.age = age;
this.sing = function() { alert(this.name) }
}
Let’s talk about the understanding of This object.
This is a keyword in js. The value of this will change as the function is used in different situations.
But there is a general principle, that is, this refers to the object that calls the function.
ThisIn general: it is the global object Global. As a method call, then this refers to this object
What is the event? What is the difference between the event mechanisms of IE and Firefox? How to stop bubbling?
1. An operation we perform on the web page (some operations correspond to multiple events). For example: when we click a button, an event will be generated. is behavior that can be detected by JavaScript.
2. Event processing mechanism: IE is event bubbling, Firefox is event capturing;
3. ev.stopPropagation();
What is closure (closure) and why? Use it?
After executing say667(), the internal variables of the say667() closure will exist, but the internal variables of the closure internal function will not exist. This will prevent the Javascript garbage collection mechanism GC from reclaiming the space occupied by say667(). resources, because the execution of the internal function of say667() depends on the variables in say667(). This is a very straightforward description of the role of closure.
function say667() {
// Local variable that ends up within closure
var num = 666;
var sayAlert = function() { alert(num); }
num ;
return sayAlert;
}
var sayAlert = say667();
sayAlert()//The execution result should pop up What does 667
"use strict"; mean? What are the advantages and disadvantages of using it?
How to determine whether an object belongs to a certain class?
Use instanceof (to be improved)
if(a instanceof Person){
alert('yes');
}
new operation What exactly does the symbol do?
1. Create an empty object, and the this variable refers to the object, and also inherits the prototype of the function.
2. Properties and methods are added to the object referenced by this.
3. The newly created object is referenced by this, and this is returned implicitly at the end.
var obj = {};
obj.__proto__ = Base.prototype;
Base.call(obj);
In Javascript, there is a When a function is executed and the object is searched, the prototype will never be searched. What is this function?
hasOwnProperty
Understand JSON?
JSON (JavaScript Object Notation) is a lightweight data exchange format.
It is based on a subset of JavaScript. The data format is simple, easy to read and write, and takes up little bandwidth
{'age':'12', 'name':'back'}
What are the ways to delay loading in js?
defer and async, dynamic creation of DOM (most commonly used), asynchronous loading of js on demand
What is ajax?
What is the difference between synchronous and asynchronous?
How to solve the cross-domain problem?
jsonp, iframe, window.name, window.postMessage, setting proxy page on the server
How to do modularization?
Execute the function immediately without exposing private members
var module1 = (function(){
var _count = 0;
var m1 = function(){
/...
};
var m2 = function(){
;
};
})();
What is the difference between AMD (Modules/Asynchronous-Definition) and CMD (Common Module Definition) specifications?
What are the methods of asynchronous loading?
(1) defer, only supports IE
(2) async:
(3) Create script, insert into DOM, callBack after loading is complete
The difference between document.write and innerHTML
document.write can only redraw the entire page
innerHTML can redraw part of the page
.call() What is the difference between .apply() and .apply()?
In the example, add is used to replace sub, add.call(sub,3,1) == add(3,1), so the running result is: alert(4);
Note : Functions in js are actually objects, and the function name is a reference to the Function object.
function add(a,b)
{
alert(a b);
}
function sub(a,b)
{
alert(a b); (a-b);
}
add.call(sub,3,1);
What is the difference between Jquery and jQuery UI?
*jQuery is a js library that mainly provides selectors, property modification, event binding, etc.
*jQuery UI is a plug-in designed based on jQuery and taking advantage of jQuery’s extensibility.
Provides some commonly used interface elements, such as dialog boxes, dragging behaviors, size changing behaviors, etc.
Have you seen the source code of JQuery? Can you briefly talk about its implementation principle?
How to convert an array into a json string in jquery and then back again?
This function is not provided in jQuery, so you need to write two jQuery extensions first:
$.fn.stringifyArray = function(array) {
return JSON.stringify(array )}
$.fn.parseArray = function(array) {
return JSON.parse(array)
}
Then call:
$( "").stringifyArray(array)
Optimization method for jQuery?
*The performance of Class-based selectivity is very expensive compared to the Id selector because it needs to traverse all DOM elements.
*DOM that is frequently operated should be cached first and then operated. It's better to use Jquery's chain call.
For example: var str=$("a").attr("href");
*for (var i = size; i < arr.length; i ) {}
The for loop searches for the .length property of the array (arr) each time it loops. Setting a variable to store this number when starting the loop can make the loop run faster:
for (var i = size, length = arr.length; i < length; i ) {}
Scope and variable declaration promotion in JavaScript?
How to write high-performance Javascript?
What operations will cause memory leaks?
A memory leak refers to any object that persists after you no longer own or need it.
The garbage collector scans objects periodically and counts the number of other objects that reference each object. If the number of references to an object is 0 (no other object references the object), or the only reference to the object is circular, then the object's memory can be reclaimed.
If the first parameter of setTimeout uses a string instead of a function, it will cause a memory leak.
Closure, console log, loop (when two objects refer to each other and retain each other, a loop will be generated)
JQuery can bind multiple events to an object at the same time. This How is it achieved?
欢迎选择我的课程,让我们一起见证您的进步~~