The print result of fn(2)(4) is 8
function (a) {
return function (b) {
console.log(a*b)
}
}
fn(2)(4)
Copy the code
What is a prototype chain
Every object initializes a property inside of it, called prototype. When we access an object’s property, if the property doesn’t exist inside the object, the object will look for the property in Prototype, which in turn will have its own prototype. And so the search goes on and on, and that’s what we call the prototype chain.
Relationship: the instance. The constructor. The prototype = instance. The proto
positioning
What are the attributes of position
Static: Default property value, layout according to standard flow (including float).
Relative: called relative position, the use of relative box position is usually based on the layout of standard quantity, then the box relative to it in the original standard position of a specified distance. Relative positioning is still in the standard flow, and it has no effect on the parent and sibling boxes.
Absolute: The position of a box is offset from its containing box. Absolute positioning is removed from the standard flow and is based on its last positioned ancestor element. If no ancestor element has been located, the location is based on the browser window. Inherit: Specifies that the value of the position property be inherited from the parent element.
Fixed: Similar to absolute positioning, positioning is performed based on the browser window. When you drag the scroll bar of the browser window, the position remains the same.
Sticky: Sticky positioning is a mixture of relative positioning and fixed positioning. The element is positioned relative before crossing a specific threshold, and then fixed.
What are the life cycles of vUE
The beforeCreate component instance is created. Created component instance is created. Properties are bound. The DOM is not generated. BeforeMount Template compilation BeforeMounting Template compilation after mounting beforeUpdate Component updating Updated Component updating After update Deactivated is invoked when the component is activated Called when keep-alive is removed. BeforeDestroy is called when a Destroyed component is destroyed and an errorCapture error is called after the destroyed component is destroyedCopy the code
What’s the difference between browser standard mode and weird mode
Before the standardization of HTML and CSS was completed, various browsers had different implementations of HTML and CSS parsing, and many old web pages were designed according to these non-standard implementations. After the determination of HTML and CSS standards, browsers should support HTML and CSS according to the standards on the one hand, and ensure the backward compatibility of non-standard old web design on the other hand. As a result, modern browsers typically have two rendering modes: standard and weird. In standard mode, the browser parses and renders documents according to HTML and CSS standards. In weird mode, the browser parses and renders the document according to the old, non-standard implementation. This way, for old web pages, the browser turns on the weird mode and the old web page displays normally. For a new web page, you can enable standard mode, which enables the new page to use the standard features of HTML and CSS.
In standard mode, the total width of a block = width + margin + padding + border
In weird mode, the total width of a block = width + margin(i.e. width already includes padding and border values)
The difference between declarative and expression functions
function a () {
return 'Function declaration';
}
var b = function () {
return 'Function expression';
}
Copy the code
Function declarations are different from function expressions in Javascript. Function declarations promote functions during JS parsing, so functions can be called in the same scope regardless of where the function declaration is defined. The value of a function expression is determined at JS runtime, and the function cannot be called until the expression assignment is complete.
Js which operations perform implicit conversions
Numeric values are automatically converted to strings
var a = 123;
alert(a+'4'); // Output 1234 "+" as a hyphenCopy the code
Strings are automatically converted to numbers
var b = 1;
alert(b-'1'); // subtract 0 alert(b*'2'); // The multiplication output is 2 alert(b/'1'); // Division output 1 alert(b%'1') // Finalizes output 0Copy the code
Type conversion of ++ and –
var c = '10'; c++; alert(c); 11 var d ='10'; d--; alert(d); / / output 9Copy the code
Type conversion of comparison operators
alert('10'> 1) // Outputtrue
alert('10' > '20') / / outputfalse
Copy the code
Conversion of the equal operator
alert('10'== 10) // Outputtrue
alert('10'=== 10) // Outputfalse
Copy the code
“!” Operator conversion
alert(!true); / / outputfalse
alert(!false); / / outputtruealert(! 100); / / outputfalse
alert(!'Hahahahaha'); / / outputfalse
Copy the code
Conversions between other operators return NaN
alert('Hahaha'-10) // Output NaNCopy the code
Use javascipt to write a method to simulate the implementation of bind method
//bind() creates a new function. // When this new function is called,bindThe first argument to () will be its runtime this // and the subsequent sequence of arguments will be passed as its arguments before the arguments passed. (from the MDN) Function. The prototype. FakeBind =function(context) {
if(typeof this ! = ="function") {
throw new Error("Bind must be called on a function");
}
letself = this; // Get parameters other than the first onelet args = Array.prototype.slice.call(arguments, 1);
let inner = function() {// Get the argument passed when the return function is executedletinnerArgs = Array.prototype.slice.call(arguments); // 1 new, this refers to the instance. At this timebindWhen, the value of this specified should be invalidated; // 2 The instanceof constructor returns the valuetrue,false, determine if it is a new call; // 3 The anonymous function calls this directly to the global object. The binding of this should be modified at this pointreturnself.apply( this instanceof inner ? this : context, args.concat(innerArgs) ); }; // inner. Prototype = this.prototype // This. Prototype = this.prototype // This. Protptype is safe with an anonymous function. Just draw a diagram of the prototype chain. / / note (2)let fNOP = function() {};
fNOP.prototype = this.prototype;
inner.prototype = new fNOP();
return inner;
};
Copy the code