Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Type Recognition

3,684 views

Published on

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.

Published in: Education
  • Login to see the comments

Type Recognition

  1. 1. TYPE RECOGNITION
  2. 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. 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. 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. 5. var extendWithName = function (object, name) { if (typeof object == "object") { object.name = name; } };
  6. 6. extendWithName(null, "null"); var a = function () {}; extendWithName(a, "function");
  7. 7. WHAT IS YOUR TYPE?
  8. 8. ARE YOU AN OBJECT?
  9. 9. ARE YOU A NUMBER?
  10. 10. var is = function (o, type) { type = (type + "").toLowerCase(); return (type == "object" && o === Object(o)) || (type == "undefined" && typeof o == type) || (type == "null" && o == null) || Object.prototype.toString.call(o) .slice(8, -1).toLowerCase() == type; };
  11. 11. THANK YOU

×