您的位置:首页 > Web前端 > JavaScript

javascript需要记忆又容易被忽视的基础

2017-02-22 08:16 357 查看

本文只做偶尔翻看记忆

区分大小写
标识符
第一个字符必须是一个字母、下划线或一个美元符号。

其他字符可以使字母、下划线、美元符号或数字。

数据类型
5种简单数据类型:Undefined、Null、Boolean、Number、String

1种复杂数据类型:Object

创建global对象

var global = function(){
return this;
}();


获取数组最大最小值

var arr = [3,4,6,7,8,3,2,5];//数字或字符串皆可
var max = Math.max.apply(Math , arr);
Array.prototype.max = function(){
var max = Math.max.apply(Math , this);
return max;
}
var arr = [3,4,6,7,47,3,2];
console.log(arr.max());


数据属性

configurable 是否能通过deltete删除

enumerable 是否能通过for-in循环

writable 是否能修改

value

Object.defineProperty()

如果通过defineProperty()设置属性为false只有第一次调用defineProperty()才生效,再次调用修改相同的属性可能会报错。

var person = {};
Object.defineProperty(person , 'name' , {
writable : false,
value : 'magic'
});
console.log(person.name);//magic
person.name = 'bob';
console.log(person.name);//magic


与之类似的还有访问其属性。get,set也可以通过defineProperty()设置。

读取属性特点

Object.getOwnPropertyDescriptor()。 接受两个参数 , 要读取的对象, 要读取的属性名称。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  javascript