一些被忽略的html小知识(持续更新)

1.section

section的width规范指示浏览器应当使用窗口的85%(无论是什么浏览器)

2.P

p的规范设置段落宽度为250像素。

3.a

a标签的理解应该是一个锚点(anchor)

4.Object.getOwnPropertyDescriptor

let myObject = {
	a:12
}
Object.getOwnPropertyDescriptor(myObject,"a")

{
	value:2,
	writable:true,
	enumerable:true,
	configurable:true
}

1.writable

writable决定是否可以修改属性的值

Object.getOwnPropertyDescriptor(myObject,"a")

{
	value:2,
	writable:false,
	enumerable:true,
	configurable:true
}

myObject.a = 3;
myObject.a ;	//2

严格模式会出现TypeError错误

2.configurable

只要属性是可以配置的,就可以使用defineProperty(…)的方法来修改属性描述符

Object.getOwnPropertyDescriptor(myObject,"a")
Object.defineProperty(Obj,"a",{
	value : 2,
	// writable configurable enumerable
	writable:true,
	enumerable:true,
	configurable:false
})
{
	value:2,
	writable:true,
	enumerable:true,
	configurable:false
}

myObject.a = 3;
myObject.a ;	//3

修改configurable属性会产生TypeError错误

注意,即使属性configurable:false,我们还是可以把writable的状态从true改成false,但是无法将false改成true

除了无法修改,configurable还会禁止删除这个属性

3.enumerate

这个描述符控制的是属性是否会出现在对象的属性枚举中,比如for…in循环,如果设置为false,这个属性就不会出现在枚举中。

另一种方式是通过

obj.propertyIsEnumerable("a") //true

来判断。
propertyIsEnumerable会检查给定的属性名是否直接存在于对象中(而不是原型链中)并且满足enumerate:true
或者:

Object.keys(obj)  //["a"]
Object.getOwnPropertyNames(obj)  //["a","b"]

Object.keys返回数组,包含所有可枚举属性。
Object.getOwnPropertyNames返回所有属性,无论是否可枚举。

5.不变性

a.定义对象常量

结合writable:false,configurable:false

b.禁止扩展

let Obj = {
	a : 1
}
Object.preventExtensions(Obj);
Obj.b= 3;
Obj.b // undefined

c.密封

Object.seal()
相当于调用preventExtensions()并且把现有属性configurable标记为false,所以密封的结果就是对象不仅不能添加新属性,而且也不能删除任何已有属性。(可以修改值)

d.冻结

Object.freeze()
相当于调用Object.seal()并且设置writable:false,禁止全部操
作。

6. in和getOwnProperty()

in操作符会检查属性是否在对象及其prototype原型链中,相比之下,getOwnProperty()只会检查属性是否在对象中,不会检查原型链。

(持续更新)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值