I'm developing a small library to learn more about javascript
I am using a chaining pattern:
(function(window) {
var myLibrary = function(iD) {
var e = document.getElementById(iD),
methods = {
one: function(val) {
e.innerHTML = val;
return this; // maintain chainability
},
two: function(val) {
alert(val);
return this; // maintain chainability
}
};
return methods;
};
window.myLibrary = myLibrary;
})(window);
chaining is fine, but I can not use an internal property of JavaScript. for example
myLibrary("ID").length
any idea to return the item?
.lengthto represent? You're always retrieving one (or zero) element (byid)...so it wouldn't make sense to represent the number of elements found (like how jQuery does it).