做网站图片太大好吗seo的定义
对于(1)中最后一个包装方式创建的是一个方法,我们必须以方法调用的方式来使用它,这和其他默认的以属性返回结果略有不同,如果有强迫症的童鞋有些伤不起,那么我们下面就把它实现为属性返回的方式:
//children是默认属性,遂起一个中文糊糊的名字 :)
HTMLElement.prototype = {get: function childrens(){var elts = [];for(let elt = this.firstChild;elt!=null;elt=elt.nextSibling){elts.push(elt);}return elts;}
}my_p.childrens;
我们还可以用看上去更优雅的方式:
//在一个函数内部调用以撇清全局对象空间
(function(){function get_childrens(){var elts = [];for(let elt = this.firstChild;elt!=null;elt=elt.nextSibling){elts.push(elt);}return elts;}//甚至我们可以写一个setter方法:function set_childrens(new_childrens){//实现略 :) }if(Object.defineProperty){Object.defineProperty(Element.prototype,"childrens2",{get:get_childrens,set:set_childrens,enumerable:false,configurable:true});}else{Element.prototype.__defineGetter__("childrens2",get_childrens);Element.prototype.__defineSetter__("childrens2",set_childrens);}
})();
my_p.childrens2