Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6007379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:40:21+00:00 2026-05-23T01:40:21+00:00

Hey I’m new to JavaScript, I love the MyClass.class and MyClass.methods in Ruby, are

  • 0

Hey I’m new to JavaScript, I love the MyClass.class and MyClass.methods in Ruby, are there any equivalence in JavaScript to check out the object type and methods available?

BTW the typeof operator seems to always return 'object', I don’t know why.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T01:40:22+00:00Added an answer on May 23, 2026 at 1:40 am

    Are there any equivalence in JavaScript to check out the object type..

    The typeof operator does that, but it can be confusing with what it reports back.

    For example, typeof null will tell you 'object', though it is not an object (though this behaviour is defined).

    typeof 'a' will tell you 'string', but typeof new String('a') will tell you an 'object'.

    The other advantage of typeof operator is it will not throw a ReferenceError if its operand has not yet been declared.

    The methods used below to determine a function can be adapted to report the correct type (though typeof is generally enough for primitives).

    …and methods available?

    You can view all the properties on an object with a for ( in ) loop.

    for (var prop in obj) {
       console.log(prop);
    }
    

    This will show all enumerable properties, including ones inherited/delegated. To disregard inherited properties, add this to the body of the loop…

    if ( ! obj.hasOwnProperty(prop)) {
       continue;
    }
    

    To view methods (properties assigned a function), you can do this…

    for (var prop in obj) {
        if (!obj.hasOwnProperty(prop) || Object.prototype.toString.call(obj[prop]) != '[object Function]') {
            continue;
        }
       console.log(prop, obj[prop]);
    }
    

    jsFiddle.

    If not in a multi window environment (i.e. not iframes), you can simply use…

    for (var prop in obj) {
        if (!obj.hasOwnProperty(prop) || ! (obj[prop] instanceof Function)) {
            continue;
        }
       console.log(prop, obj[prop]);
    }
    

    jsFiddle.

    …or…

    for (var prop in obj) {
        if (!obj.hasOwnProperty(prop) || obj[prop].constructor != Function) {
            continue;
        }
       console.log(prop, obj[prop]);
    }
    

    jsFiddle.

    If you only care about methods that implement [[Call]] (i.e. can be invoked as a function), such as the RegExp objects in older Safaris, you can simply determine what is invokable with typeof fn == 'function'.

    Since you mentioned Ruby, you could be completely crazy and implement Ruby’s class (or close enough) and methods by augmenting Object.prototype, but please don’t. 🙂

    I also have an in-depth article on the typeof operator in JavaScript.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey, in the Programming Pearls book, there is a source code for setting, clearing
Hey there, I'm at the moment trying to make a product management application. The
Hey I am very new to Web Programming. I have been learning PHP from
Hey everyone, I'm using Virtual PC and working with a virtual hard disk (*.vhd)
Hey so what I want to do is snag the content for the first
Hey, I'm using Levenshteins algorithm to get distance between source and target string. also
Hey all, my Computational Science course this semester is entirely in Java. I was
Hey, I've been developing an application in the windows console with Java, and want
Hey all. Newbie question time. I'm trying to setup JMXQuery to connect to my
Hey peoples, I've been studying Java for a couple of weeks, and have decided

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.