-
對(duì)象代理 進(jìn)行對(duì)原有的數(shù)據(jù)過(guò)濾保護(hù)
查看全部 -
//ES5
Object.defineProperty(window,""PI,{
????????????????value:5555,
????????????????writable:false
});
ES6:
????const PI = 44444444;
查看全部 -
//ES5利用defineProperty這個(gè)api達(dá)到只讀效果
var Person={
????name:'person',
????age:15
};
Object.defineProperty(Person,'sex',{
????writable:false,
????value:'male'
});
console.table({
name:Person.name, age:Person.age, sex:Person.sex
}); //輸出結(jié)果
Person.name='es5-cname';
console.table({...});? //測(cè)試修改名字
try{
Person.sex='female';
console.table({...});? //報(bào)錯(cuò),因?yàn)閟ex是只讀
}catch(e){
console.log(e);
}
查看全部 -
ES5 |ES6合并數(shù)組
查看全部 -
ES3、5可變參數(shù)
通過(guò)arguments獲取當(dāng)前參數(shù)的參數(shù)列表
function f(){
var a=Array.prototype.slice.call(arguments);
var sum=0;
a.forEach(function(item){
sum+=item;
});
return sum;
}
console.log(1,2,3);
查看全部 -
檢查X(函數(shù)的必選參數(shù))是不是已經(jīng)賦值
function checkParameter(){
throw new Error('can\'t be empty');
}
function f(x=checkParameter(),y=7,z=9){
return x+y+z;
}
try{
f();
}catch(e){
console.log(e);
}finally{
}
查看全部 -
//es3、5默認(rèn)參數(shù)
function f(x,y,z){
????if(y===undefined){
? ? y===7;
????}
? ? if(z===undefined){
? ? z===40;
????}
return x+y+z;
}
console.log(f(1)); //1+7+40
//console.log(f(1,3)) 輸出結(jié)果1+3+40
查看全部 -
ES6開發(fā)環(huán)境-win|mac
查看全部 -
ES5中,this指向調(diào)用者;ES6箭頭函數(shù)中的this指向定義時(shí)的上下文
查看全部 -
學(xué)前準(zhǔn)備github地址
查看全部 -
ES6的寫法:
function f(...a){
????var sum = 0;
????a.forEach(item=>{
????????sum += item * 1;
????}
????return sum;
}
查看全部 -
function f(){
var a = Array.prototype.slice.call(arguments);
var sum = 0;
a.forEach(function(item){
sum += item*1;
})
return sum;
}
console.log(f(1,2,3,6));
查看全部 -
調(diào)式輸出:
console.log(f(1));
查看全部 -
關(guān)閉eslint:
/* eslint-disable */
查看全部 -
https://github.com/cucygh/fe-material
查看全部
舉報(bào)