15 min talk about importance of correct type recognition in methods of public APIs.
Not sure does it make any sense without narration, but anyway due to high demand, here it goes.
2. var html = function (value) {
if (typeof value == "string") {
element.innerHTML = value;
}
if (typeof value == "function") {
element.innerHTML = value();
}
if (value == null) {
return element.innerHTML;
}
return element;
};
3. var a = {
value: "I am an object",
toString: function () {
return this.value;
}
};
var b = new String("I am a string");
alert(a);
el.html(a);
alert(b);
el.html(b);
4. var html = function (value) {
if (typeof value == "function") {
element.innerHTML = value();
} else if (value == null) {
return element.innerHTML;
} else {
element.innerHTML = String(value);
}
return element;
};
5. var extendWithName = function (object, name) {
if (typeof object == "object") {
object.name = name;
}
};