`
Blackbaby
  • 浏览: 179906 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

JavaScript:The Class of an Object

阅读更多
function is(type, obj) { 
    var clas = Object.prototype.toString.call(obj).slice(8, -1); 
    return obj !== undefined && obj !== null && clas === type; 
} 
 
is('String', 'test'); // true 
is('String', new String('test')); // true 

 

 

   In the above example, Object.prototype.toString gets called with the value of this being set to the object whose [[Class]] value should be retrieved.

分享到:
评论

相关推荐

    JavaScript Best Practice

    The Anatomy of a Modern JavaScript Application by James Kolce Clean Code with ES6 Default Parameters & Property Shorthands by Moritz Kruger JavaScript Performance Optimization Tips: An Overview by ...

    javascript.the.definitive.guide.5th.2006(英文版)

    This book is both an example-driven programmer's guide and a keep-on-your-desk reference, with new chapters that explain everything you need to know to get the most out of JavaScript, including: ...

    Sortable前端框架

    * put: `true|false|["foo", "bar"]|function` — whether elements can be added from other lists, or an array of group names from which elements can be taken. * revertClone: `boolean` — revert cloned ...

    JavaScript权威指南(第五版).chm

    This book is both an example-driven programmer's guide and a keep-on-your-desk reference, with new chapters that explain everything you need to know to get the most out of JavaScript, including: ...

    C++调用JavaScript

    In any case, it is possible to make a control for the JavaScript object inside an HTML page by using a traditional COM approach. This article describes the class CWebPage that allows you to do it and...

    OO4O(Oracle Objects for OLE C++ Class Library)

    Oracle Objects for ... OO4O consists of an in-process COM Automation Server, the C++ class library, and the Oracle Data Control. Relationships shows the high-level relationship between OO4O components.

    JavaScript权威指南第五版【新】(犀牛书)

    This book is both an example-driven programmer's guide and a keep-on-your-desk reference, with new chapters that explain everything you need to know to get the most out of JavaScript, including: ...

    The Dart Programming Language

    Dart is a class-based, object-oriented language that simplifies the development of structured modern apps, scales from small scripts to large applications, and can be compiled to JavaScript for use in...

    JavaScript权威指南

    An Overview of the DOM Section 17.2. Using the Core DOM API Section 17.3. DOM Compatibility with Internet Explorer 4 Section 17.4. DOM Compatibility with Netscape 4 Section 17.5. Convenience ...

    Python Cookbook英文版

    5.13 Modifying the Class Hierarchy of an Instance 5.14 Keeping References to Bound Methods Without Inhibiting Garbage Collection 5.15 Defining Constants 5.16 Managing Options 5.17 ...

    Smart Mobile Studio Enterprise v2.0 Build 723 Cracked

    You have reached the home of Smart Mobile Studio, a very exciting project that allows you to write ordinary Pascal in the flavour made famous by Delphi and Free Pascal, but generate feature rich, ...

    AJAX and PHP.pdf

    instance, and static class members in JavaScript, what the JavaScript execution context is, how to implement inheritance by using constructor functions and prototyping, and the basics of JSON. ...

    The.Dart.Programming.Language.03219277

    Dart is a class-based, object-oriented language that simplifies the development of structured modern apps, scales from small scripts to large applications, and can be compiled to JavaScript for use in...

    IntraWeb v14.0.23 Ultimate for RAD Studio XE-XE5 (x32+x64)

    A Slim Reader/Writer lock object is used in TIWStandAloneServer and TIWServerInternalFiles instead of TMultiReadExclusiveWriteSynchronizer object. This new lock is available under Windows Vista and up...

    外文翻译 stus MVC

    if not, it will create an instance of the class. • Struts will set the state of the UserActionForm using corresponding fields from the HttpServletRequest. No more dreadful request.getParameter() ...

    BobBuilder_app

    I also tried an assorted number of sorting routines like double pivot quick sort, timsort, insertion sort and found that they all were slower than the internal .net quicksort routine in my tests. ...

    谷歌地图 delphi 封装库 2013 0.1.9 全面支持google maps api

    - Bug fixed: TGMMap -> bug fixed on RemoveLinkedComponent when trying delete an object without being the list created. - Bug fixed: JavaScript => when it had figures of different types together, ...

    Beginning Microsoft Visual CSharp 2008 Wiley Publishing(english)

    Creating an Installation Package for the SimpleEditor 639 Building the Project 654 Installation 654 Summary 659 Exercises 660 Part III: Web Programming 662 Chapter 19: Basic Web ...

    Introduction to JVM Languages

    However, increasing the complexity of the language and improving the performance of the JVM created an opening for a new generation of programming languages. If you want to build a strong foundation...

    JavaScript内核系列

    而当 AJAX流行起来之后,更多的非常绚丽的WEB应用涌现了,而且呈越来越多的趋势,如Gmail,Google Map,Google Reader,Remember the milk,facebook等等优秀的WEB2.0应用,都大量的使用了JavaScript及其衍生的技术...

Global site tag (gtag.js) - Google Analytics