发布于 2020-08-06 10:37:06
来自文档
与函数表达式相比,箭头函数表达式(也称为fat箭头函数)的语法更短,并在词汇上绑定此值。
在您的示例中,this被绑定到window对象。
使用正则函数的
HTMLElement.prototype.attr = function(pAttributeName, pAttributeValue) {
if (pAttributeValue) {
this.setAttribute(pAttributeName, pAttributeValue);
} else {
return this.getAttribute(pAttributeName);
}
};
document.querySelector('h1').attr('id', 'head')#head {
color: red;
}<h1>Heading</h1>
https://stackoverflow.com/questions/63281588
复制相似问题