In the JavaScript,
Major browsers
The browser | The kernel |
---|---|
IE | trident |
chrome | webkit=>blink(webkit) |
safari | webkit |
firefox | Gecko (gecko) |
opera | presto |
Browser history and JS birth
- 1990
- Tim Berners-Lee is someone who shares information with hypertext
world wide web
Migration toC libwww/neus
Allow others to view websites written by others - 1993
- University of Illinois NCSA blocks (Mark Anderson)MOSIAC browser from displaying images in graphical browsers
- 1994
- Mark Anderson and Jim Gilac silicon Valley SGI
- MOSIAC communication corporation
- Netscape Navigator ->2003
- 1996
- Microsoft buys Spy Glass
- IE internet exploror 1.0
- With IE 3 came Jscript, the first scripting language
- Brendan Eich at NETSCAPE
- Livescript was developed by NAVIGATOR
- 2008
- V8 engine
- Direct translation machine code
- Run independently of the browser
- V8 engine
- Tim Berners-Lee is someone who shares information with hypertext
A programming language
- A compiled
- Translation process: source -> compiler -> machine language -> executable
- advantages
- Fast running speed
- disadvantages
- Cross-platform requires recompilation
- interpreted
- Translation process: source code -> interpreter -> explain a line to execute a line
- advantages
- There is no need to recompile for different platforms
- disadvantages
- Slow running speed
Scripting language
Dynamic languages -> Scripting languages -> Interpreted languages -> weakly typed languages
Static -> compiled -> weakly typed
-
Scripting language -> scripting engine -> interpreter front and back
JavaScript: Client-side scripting The JavaScript interpreter is on the browser
PHP: Server-side scripting The PHP interpreter is on the server
Python can be compiled into other types of languages through the interpreter
- Such as Jython, retaining
ECMA
Specification for the European Computer Manufactures Association(European Computer Manufacturing Association) ECMA-262 Scripting language ECMAScript ES5, ES6 Standardized scripting language
Single thread => Simulate multithreading
Single thread -> only one thing can be done at a time
Multithreading -> Can do more than one thing at a time
- Javascript engines are single-threaded
- Rotation time slice
- Take turns executing multiple task segments in a short time
- Task 1 Task 2
- Shard task 1 task 2
- Randomly arrange these task fragments into a queue
- The task fragments are sent to the JS process in this queue order
- The JS thread executes one line after another
coupling
Single accountability for high cohesive, low coupling modules
A block or module is highly functional and highly independent
decoupling
JavaScript key
- ECMAScript
- Syntax, variable keywords, reserved words, values, primitive types, reference types
- DOM(Document Object Model) Document object model
- W3C specification to add, delete, and change labels
- BOM (Browser Object Model) Browser object model
- No corresponding specification can be written compatible
- Because each browser vendor is different, there is no specification
- The event
- No corresponding specification can be written compatible
The value of JS
- Raw value -> Basic type
- Number
- String
- Boolean
- undefined
- null
- Reference value
- object
- array
- function
- date
- RegExp
Determine type
typeof
console.log(typeof(a)) // if a is undefined, it is undefined
console.log(typeof(typeof(a)) // Typeof returns a string
Copy the code
Declare a variable
Parenthesis operation > Normal operation > Assignment
function
The basic function
// The basic function declaration
function text (parameter){
// Execute the statement
}
// Anonymous function expressions function literals
var text = function text1 (){
// Execute the statement
Text1 is not visible
}
// Parameter -> placeholder -> formal placeholder -> formal parameter -> parameter
function test(a,b){
// An error is reported if this parameter is not passed
// The parameter is equivalent to declaring inside a function such as var a
console.log( a + b )
}
// Actual parameters => In sequence => The change of position is invalid
// If you pass extra arguments in a function call argument that are not equal to the number of parameters, no error is reported
test(11.22)
function test(a,b){
b = 3
console.log( arguments[1])// Undefuned is printed
// If the parameter is not passed in => b= > undefined => undefined cannot be assigned
If you pass a value in an argument -> you can change the value inside the function -> If you do not pass a value in the argument -> you cannot change the value inside the function
}
test(1)
function test(a,b){
a = 3
console.log( arguments[0])// Arguments [0
// Arguments are stored in stack memory
// Arguments are mapped to the values of arguments (); // Arguments are mapped to the values of arguments () Arguments [0] can also change because of one-to-one correspondence
}
test(1.2)
Copy the code
Every function must have a return. If you don’t write a return, the JS engine adds a return at the end of the function by default
The use of the return
- Terminate function execution, where do you want to terminate
return
Where is the writing - Return any value
Global variables VS local variables
- Global declarations are called global variables
- Declarations inside functions are called local variables
- You can use global variables in a function and cannot call variables in a function globally
Functional programming
- A fixed function or process by which a program is encapsulated, implementing a fixed function or program in this package
You need an exit and an entrance
- The entry is the parameter and the exit is the return value
The function initializes arguments
Default value of initialization parameter :undefined
// a = 1 is es6 syntax
function test(a=1,b){
console.log(a,b)
// A is 1, b is 22
// Arguments are mapped to parameters. Arguments take the value of undefined and conversely arguments take the value of undefined
}
test(undefined.22)
Copy the code
precompiled
- Check for grammatical errors throughout
- Precompilation process
- Explain a line, execute a line
Functions declare global promotion, variables only declare promotion, assignment does not promote
Implied global variable
imply global variable
// If a variable is assigned an undeclared value, it will be mounted to the global object Window
b = 22
console.log(window.b)
Copy the code
AO activation object
Active object, function execution context
- Creates an AO object and looks for the parameters and variable declarations in the function
- Find the parameter value of the argument and assign it to the parameter
- Look for function declarations inside functions
- perform
function fn (a){
var a = 1
function a (){}
}
fn(2)
AO = {
// a:undefined
// a:2
a : function a (){}}Copy the code
If there is no such value in AO, GO will look for it
GO global object
Global execution context
- Finding variable declarations
- Find a function declaration
- perform
GO
===window
var fn1 = 123
function fn1(){}
GO: {// fn1 : undefined
fn1 : function fn1(){}}Copy the code