函数分类
-
普通函数
function func(){
}
-
匿名函数
setInterval(function(){
console.log(123);
},5000)
-
自执行函数
(function(arg){
console.log(arg);
})(1)
序列化
-
把一个对象转换成字符串
JSON.stringify(li)
.png)
-
字符串转换为对象
JSON.parse(s)
.png)
转义
客户端(cookie) ==》》请求服务器端
将数据经过转义后,保存在cookie中
decodeURI( ) URl中未转义的字符
decodeURIComponent( ) URI组件中的未转义字符
encodeURI( ) URI中的转义字符
encodeURIComponent( ) 转义URI组件中的字符
escape( ) 对字符串转义
unescape() 给转义字符串解码
URIError 由URl的编码和解码方法抛出
eval
执行eval和exec
时间
Date类
var d = new Date()
作用域
1、以函数作为作用域
2、函数的作用域在函数未被调用之前就已经创建
3、函数的作用域存在作用域链,并且也是在调用之前就创建了
4、函数内局部变量提前声明
面向对象
例如
function Foo(n){
this.name = n;
}
var obj = new Foo("we");
-
this指代对象(python中的self)
-
创建对象时,new函数()
原型
1 function Foo(n){ 2 this.name = n; 3 } 4 5 Foo.prototype = { 6 'sayName':function(){ 7 console.log(this.name) 8 } 9 } 10 11 obj1 = new Foo('we'); 12 obj1,sayName() 13 14 obj2 = new Foo('wee');