Version awareness
- ECMA Script (developed by the ECMA organization) is the specification, and JavaScript is the implementation.
- ES5 (2009) 、 ES6 (2015) 、 ES7 (2016)
- IE browser has some support problems for ES5.
1. Strict mode ('use strict'): Make Javascript run under stricter grammatical conditions
- Variable: declaration must use var
- Object: attributes cannot be repeated
- Function: The custom function this cannot point to the window object, add scope to the eval function
2. json: The syntax for storing and exchanging text information
- json.stringFy(): javascript object/array to json text.
- json.parse(): Convert json text to javascript object/array.
Three. Object extension
- 1.Object.create(prototype, [descriptors]): Create a new object with the specified object as the prototype
var obj = {
firstName:"张",lastName:'三'};
var newObj = null;
newObj = Object.create(obj,{
sex:{
value:"男",
writable:true,
configurable:true,
enumerable:true
}
});
![[External link image transfer failed. The source site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-AEmtv36D-1583675311642) (C:\Users\ASUS\Desktop\md notes\Silicon Valley front end\5 standard integration \ES_567\assets\1583551448985.png)]](https://img-blog.csdnimg.cn/20200308215533513.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2p3MjI2ODEzNjU3MA==,size_16,color_FFFFFF,t_70)
- 2.Object.defineProperties(object, descriptors): extend multiple properties for the specified object
var strongObj = {
firstName:"张",
lastName:'三',
get fullName(){
return this.firstName+this.lastName;
},
set fullName(name){
var arr = name.split("");
this.firstName = arr[0];
this.lastName = arr[1];
}
};
var obj = {
firstName:"张",lastName:'三'};
var strongObj1 = {
firstName:"张",lastName:'三'};
Object.defineProperties(strongObj1,{
fullName:{
get:function(){
return this.firstName+this.lastName;
},
set:function(name){
var arr = name.split("");
this.firstName = arr[0];
this.lastName = arr[1];
}
}
});
![[External link image transfer failed. The source site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-B6MWwWkf-1583675311645) (C:\Users\ASUS\Desktop\md notes\Silicon Valley front end\5 standard integration \ES_567\assets\1583551569778.png)]](https://img-blog.csdnimg.cn/20200308215613295.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2p3MjI2ODEzNjU3MA==,size_16,color_FFFFFF,t_70)
Four. Array extension
- 索引:Array.prototype.indexOf/ lastIndexOf (value)
- 遍历:Array.prototype.forEach(function(item, index){})
- 映射:Array.prototype.map(function(item, index){})
- 过滤:Array.prototype.filter(function(item, index){})
var arr = [6,2,4,6,1,6];
console.log(arr.indexOf(6),arr.lastIndexOf(6));
arr.forEach(function(item){console.log(item)});
console.log(arr.map(function(item){return item+10}));
console.log(arr.filter(function(item){return item>4}));
![[External link image transfer failed. The source site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-jE9kUuVI-1583675311646) (C:\Users\ASUS\Desktop\md notes\Silicon Valley front end\5 standard integration \ES_567\assets\1583573247405.png)]](https://img-blog.csdnimg.cn/20200308215640391.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2p3MjI2ODEzNjU3MA==,size_16,color_FFFFFF,t_70)
Five. Function extension
- Function.prototype.bind(obj): bind this in the function to obj, and return the function
- Distinguish between bind, call and apply: distinguish from whether to execute immediately or pass parameters
function fn(param){
console.log(this,param);
}
var obj = {name:"张三"};
fn("param");
fn.call(obj,"call_param");
fn.apply(obj,["apply_param"]);
fn.bind(obj,"bind_param")();//不会立即执行,常用在回调函数。
![Insert picture description here](https://img-blog.csdnimg.cn/20200308215733839.png)