да не) Понял как делать:
<div id='div'>1</div>
<div>2</div>
<script>
function $() {
return {
id: function (id) {
this.elem = document.getElementById(id);
this.id = id;
return this;
},
add: function (add) {
this.elem.innerHTML += add
return this;
},
html: function () {
return this.elem.innerHTML
return this;
},
tag: function (tag, index) {
this.elem = document.getElementsByTagName(tag)[index]
return this;
},
write: function (write) {
this.elem.innerHTML = write
return this;
},
src: function () {
return this.elem.src
return this;
}
};
}
alert($().tag('div', 0).html()) /* работает, хотя раньше фаерьаг писал: html() - is not a fuction */
alert($().id('div').html()) // также работает
/* Дело в том, что раньше все ф-ии получали доступ к элементу через docu...ById(this.id)(и если мы брали элемент по тэгу, то ничего не работало), сейчас же весь элемент "храниться" в this.elem */
</script>