SlideShare a Scribd company logo
1 of 11
Download to read offline
TYPE RECOGNITION
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;
};
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);
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;
};
var extendWithName = function (object, name) {
    if (typeof object == "object") {
        object.name = name;
    }
};
extendWithName(null, "null");

var a = function () {};
extendWithName(a, "function");
WHAT IS YOUR TYPE?
ARE YOU AN OBJECT?
ARE YOU A NUMBER?
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;
};
THANK YOU

More Related Content

Viewers also liked

Test and some test types (ev elt)
Test and some test types (ev elt)Test and some test types (ev elt)
Test and some test types (ev elt)
theryszard
 
Rewards And Recognition
Rewards And RecognitionRewards And Recognition
Rewards And Recognition
rajeevgupta
 

Viewers also liked (14)

Writing Identification Tests
Writing Identification TestsWriting Identification Tests
Writing Identification Tests
 
The Power of Employee Appreciation. 5 Best Practices in Employee Recognition.
The Power of Employee Appreciation. 5 Best Practices in Employee Recognition.The Power of Employee Appreciation. 5 Best Practices in Employee Recognition.
The Power of Employee Appreciation. 5 Best Practices in Employee Recognition.
 
Test and some test types (ev elt)
Test and some test types (ev elt)Test and some test types (ev elt)
Test and some test types (ev elt)
 
Rewards & recognition
Rewards & recognitionRewards & recognition
Rewards & recognition
 
Employee recognition
Employee recognitionEmployee recognition
Employee recognition
 
sample test questionnaire in Biological Science
sample test questionnaire in Biological Science sample test questionnaire in Biological Science
sample test questionnaire in Biological Science
 
Concept of reward and total reward system
Concept of reward and total reward systemConcept of reward and total reward system
Concept of reward and total reward system
 
Gesture recognition
Gesture recognitionGesture recognition
Gesture recognition
 
Types of test
Types of testTypes of test
Types of test
 
Reward Management
Reward ManagementReward Management
Reward Management
 
Rewards And Recognition
Rewards And RecognitionRewards And Recognition
Rewards And Recognition
 
Recognition - International Law
Recognition - International LawRecognition - International Law
Recognition - International Law
 
reward-systems
reward-systemsreward-systems
reward-systems
 
Human Resource Management: Reward and compensation
Human Resource Management: Reward and compensationHuman Resource Management: Reward and compensation
Human Resource Management: Reward and compensation
 

More from Dmitry Baranovskiy (14)

The Origins of Magic
The Origins of MagicThe Origins of Magic
The Origins of Magic
 
Demystifying Prototypes
Demystifying PrototypesDemystifying Prototypes
Demystifying Prototypes
 
Raphaël
RaphaëlRaphaël
Raphaël
 
Raphaël JS Conf
Raphaël JS ConfRaphaël JS Conf
Raphaël JS Conf
 
Obvious Secrets of JavaScript
Obvious Secrets of JavaScriptObvious Secrets of JavaScript
Obvious Secrets of JavaScript
 
Your JavaScript Library
Your JavaScript LibraryYour JavaScript Library
Your JavaScript Library
 
Canvas
CanvasCanvas
Canvas
 
SVG
SVGSVG
SVG
 
Java Script Workshop
Java Script WorkshopJava Script Workshop
Java Script Workshop
 
Raphael
RaphaelRaphael
Raphael
 
Web Vector Graphics
Web Vector GraphicsWeb Vector Graphics
Web Vector Graphics
 
Typography on the Web
Typography on the WebTypography on the Web
Typography on the Web
 
Microformats—the hidden treasure
Microformats—the hidden treasureMicroformats—the hidden treasure
Microformats—the hidden treasure
 
Advanced JavaScript Techniques
Advanced JavaScript TechniquesAdvanced JavaScript Techniques
Advanced JavaScript Techniques
 

Type Recognition

  • 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; } };
  • 6. extendWithName(null, "null"); var a = function () {}; extendWithName(a, "function");
  • 7. WHAT IS YOUR TYPE?
  • 8. ARE YOU AN OBJECT?
  • 9. ARE YOU A NUMBER?
  • 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; };