Tag: date () word hard disk. So Func target object component print
First, JavaScript functions 1. Common functions
function func () {}
2. Anonymous functions
SetInterval (function () { console.log (123);},5000)
3. Self-executing functions
Most of the circumstances may introduce someone else's JS, if someone else's JS function repetition, will lead to a non-use, in order to avoid this problem, put all the functions inside the function inside. Made into a nested function.
But if the outside function name also has the repetition, how to deal with, the outside function does not have the name, and executes automatically.
How do I write a self-executing function?
() (): First parenthesis function, second parenthesis argument. Creates a function, and automatic execution (ARG) {
Second, JavaScript serialization and escape
- Common serialization operations
Li = [11,22,33,44]s = Json.stringify (LI) //Convert object to String newl = Json.parse (s) //Convert String to Object
such as online search for a thing, the URL automatically become a% and other content
> URL = "https://www.sogou.com/web?query= time"<"https://www.sogou.com/web?query= Time ">newurl = encodeURI (URL)/Escape<"https://www.sogou.com/web?query=%e6%97%b6%e9%97%b4 ">decodeURI (Newurl)//revert to original format<"https://www.sogou.com/web?query= Time ">newurl = encodeuricomponent (URL)//Escape all<the HTTPS%3a%2f%2fwww.sogou.com%2fweb%3fquery%3d%e6%97%b6%e9%97%b4 "
The default HTTP request is not a long link, even once it is broken, but the site has to remain logged on for one months, how to achieve.
After a successful login, the website will send you a string to save it somewhere on your hard drive. This is the cookie.
Client (Cookie) = "Server side." After the data has been escaped, it is saved in a cookie
Escape () //To String Escape unescape ()// to escape string decoding Urierror //By URL encoding and decoding method thrown
Three, eval and time operation
In Python:
val = eval ("+") # expression exec ("Execute code") # such as for loop. But exec just executes, no return value
In javascript:
Eval: function is a collection of eval and exec in Python
> d = new Date () Mon Nov 22:46:33 gmt+0800 (China Standard Time) > d.getminutes () 46> n = d.getminutes () + 1258> d.setminutes (n) 1480345113329> Dmon Nov 22:58:33 gmt+0800 (China Standard Time)// Date class// var d = new Date () current time// d.getxxx get// d.setxxx settings
Iv. JavaScript scope 1.javascript takes a function as a scope (except let)
- Languages such as Java, C, C # are scoped with the "{}" code block.
- In Python: scopes are scoped with functions.
- JavaScript: Also a function as a scope
2. The scope of the function has been created 3 before the function has been called. The scope of the function has a scope chain and is also created before it is called
Scope chain: Nested functions, one layer at a scope
Below are three examples of what will be output separately?
Example one: xo = "Alex"; function func () { //var xo = ' Eric '; function inner () { //var xo = ' Tony '; Console.log (XO); } Inner () } func () //Example two: xo = "Alex"; function func () { var xo = ' Eric '; function inner () { console.log (XO); } return inner; } var ret = func () ret () //Example three: xo = "Alex"; function func () { var xo = ' Eric '; function inner () { console.log (XO); } var xo = ' Tony '; return inner; } var ret = func () ret ()//Note: line break in browser console, use shift+ carriage return
The scope of a function has a scope chain and is also created before being called
4. Function internal variable declaration in advance
Example one: function func () { console.log (xxoo); } Func (); Program Direct error function func () { console.log (xxoo); var xxoo = ' Alex '; } In the process of interpretation: Var Xxoo; Func (); Undefined
Unassigned variable, declared in advance as undefined
> var fgfundefined> fgfundefined
V. JavaScript Object-oriented
- This refers to the object (Python self)
- When creating an object, the new function name ()
function Foo (n) { this.name = n; This.sayname = function () { console.log (this.name); }} var obj1 = new Foo (' we '); Obj1.nameobj1.sayName () var obj2 = new Foo (' Wee '); Obj2.nameobj2.sayName ()
That's fine, but there's a problem, and there's something that's been repeatedly defined, and the Sayname method is repeated in every object.
- Python object-oriented: methods are saved in class memory
Class Foo: def __init__ (self,name): self.name = name def sayname (self): print (self.name) obj1 = Foo (' we ') Obj2 = Foo (' Wee ')
- JavaScript Object-oriented prototypes:
Prototyping: Avoid wasting memory resources
function Foo (n) { this.name = n;} The prototype of Foo Foo.prototype = { ' sayname ': function () { console.log (this.name) }}obj1 = new Foo (' we '); O Bj1.sayname () Obj2 = new Foo (' Wee ');
Vi. parsing of JavaScript lexical analysis
The following code, respectively, will correspond to what output?
function T1 (age) { console.log (age); function age () var = +; Console.log (age); when function age () {} //Executes because there is no call, the execution does not consider console.log (age); T1 (3);
Active object--> abbreviation AO
1. Formal parameters
2. Local Variables
3. function declaration expressions (higher precedence)
The following begins the analysis:
- Formal parameters:
Ao.age = 3;
- Local variables:
Ao.age = 27;
- function declaration expressions
Ao.age = function ()
The analysis of the scope value can also be analyzed by lexical analysis.
The JavaScript sequel to the front end Obsessive Compulsive Disorder series