function create(type){ var element=document.createElement(type); //this=element; element.setStyles=function(key,prop){ this.setAttribute(key,prop); return this;//this指向element } element.getStyle=function(key){ return this.getAttribute(key); } return element; } var ele=create('div'); 那么现在ele就具有了setstyles getstyle方法 测试 ele.setStyles('color','red').setStyles('id','jk');