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

  • SEARCH
  • Home
  • 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 8933025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:26:24+00:00 2026-06-15T09:26:24+00:00

I have the following javascript code: function testClass() { this.SaveValue = function (value) {

  • 0

I have the following javascript code:

function testClass() {
    this.SaveValue = function (value) {
        var isInstance = value instanceof TestEnum;

        if (!isInstance) {
            return;
        }
     }
}

TestEnum = {
    VALUE_0: 0,
    VALUE_1: 1,
    VALUE_2: 2   
}

I create an instance of this object in the following way:

$(function () {
    var a = new testClass();
    a.SaveValue(TestEnum.VALUE_1);    
});

All I’d like to do is test that the value passed to the SaveValue function is actually the type of TestEnum. However, when I run this code I get the following error: Uncaught TypeError: Expecting a function in instanceof check, but got 1

Am I going about this the right way? I tried typeof but it only returns number which is not particularly useful to me.

  • 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-06-15T09:26:25+00:00Added an answer on June 15, 2026 at 9:26 am

    You are passing a number to the function in

    a.SaveValue(TestEnum.VALUE_1);
    

    Since TestEnum is simply an Object, and you are referencing a number property on that object, you’re calling your function with a number. You should instead create a TestEnumValue object and use that for your Object’s properties:

    JSFiddle link for below

    function testClass() {
        this.SaveValue = function (value) {
            var isInstance = value instanceof TestEnumValue;
    
            if (!isInstance) {
                return;
            }
         }
    }
    
    TestEnumValue = function(arg) {
       arg = arg ? arg : 0;  //  sensible default
    
       this.key = 'VALUE_' + arg;
       this.val = arg;
    }
    
    Level = {
        NumSpiders : new TestEnumValue(0),
        NumCreepers: new TestEnumValue(1),
        NumZombies : new TestEnumValue(2),
        NumChickens: new TestEnumValue  //  uses default enum value    
    };
    
    $(function() {
        var a = new testClass();
        a.SaveValue(Level.NumSpiders);
    
        $('#hi').text(Level.NumSpiders.key);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following Javascript code: var idJS; $('.disp').click(function () { idJS = $(this).attr(id);
I have the following Javascript code: function checkIfValid(){ var form = document.createuserform; if(form.fName.value ==
Let's say we have the following JavaScript/jQuery code below function createElement(i, value) { return
I have the following Javascript code add_num = { f: function(html, num) { alert(this.page);
I have problems with the following bit of javascript/jquery code: this.droppable = function(){ $('.imageWindow
I have the following JQuery code: <script type=text/javascript> $(document).ready(function () { var $containerHeight =
I have the following code <div class=framepage> <header> <script type=text/javascript> function getBaseUrl() { return
I have the following javascript code. var Test = function(){ $(#+elementId).click(function(){ // How to
I have the following JavaScript code: var cILo=true; var img1=images/title-2a.png; var img2=images/title-2b.png; function loadblinker()
I have the following JavaScript code: (function() { function f(){ alert(1); } return f();

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.