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 9087409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:41:25+00:00 2026-06-16T21:41:25+00:00

I have a function that uses case to return an object function GetModel(mymodel){ var

  • 0

I have a function that uses case to return an object

    function GetModel(mymodel){

    var mydatamodel = null; 
    switch(mymodel)
    {
    case 'Contact':
    mydatamodel = kendo.data.Model.define({
                                    id: "__KEY",
                                    fields: {
                                    __KEY: { type: "string" },
                                    __STAMP: { type: "number" },
                                    ID: { editable: false, nullable: true },                                                                
                                    firstName: { type: "string" },
                                    middleName: { type: "string" },                                                         
                                    lastName: { type: "string" }
                                    }                               
                                });
                                break;

    case 'Address':
    mydatamodel = kendo.data.Model.define({
                                    id: "__KEY",
                                    fields: {
                                    __KEY: { type: "string" },
                                    __STAMP: { type: "number" },
                                    ID: { editable: false, nullable: true },                                                                
                                    street: { type: "string" }
                                    }                               
                                });
                                break;
    case 'ContactType':     
    mydatamodel = kendo.data.Model.define({
                                    id: "__KEY",
                                    fields: {
                                    __KEY: { type: "string" },
                                    __STAMP: { type: "number" },
                                    ID: { editable: false, nullable: true },                                                                
                                    name: { type: "string" }                                
                                    }                               
                                });
                                break;
    };

    return mydatamodel  
    };

//Try to create new instance
var mymodel = new GetModel("Contact")

Now this function does return an object but the object is not the same as
using the below code to create a new object which is what I need

 var mydatamodel = kendo.data.Model.define({
                                    id: "__KEY",
                                    fields: {
                                    __KEY: { type: "string" },
                                    __STAMP: { type: "number" },
                                    ID: { editable: false, nullable: true },                                                                
                                    firstName: { type: "string" },
                                    middleName: { type: "string" },                                                         
                                    lastName: { type: "string" }
                                    }                               
                                });

//Create new object;
var mymodel = new mydatamodel();

This works as expected and creates a new instance of the kendoui.datamodel where
the function returns the kendoui.data.modal…. as a function and not a new instance of the object

I would like to be able to call a switch function because I want this code in a different .js file then the main .html page for code seperation. So how would
I go about getting the above function GetModel to act in the same way as the
var = kendoui.data.model… is working

Thanks,

Dan

  • 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-16T21:41:26+00:00Added an answer on June 16, 2026 at 9:41 pm

    Don’t use the new operator on your function.

    Just make the function return an instance like this:

    function GetModel(mymodel){
    
    var mydatamodel = null; 
    switch(mymodel)
    {
    case 'Contact':
    mydatamodel = kendo.data.Model.define({
                                    id: "__KEY",
                                    fields: {
                                    __KEY: { type: "string" },
                                    __STAMP: { type: "number" },
                                    ID: { editable: false, nullable: true },                                                                
                                    firstName: { type: "string" },
                                    middleName: { type: "string" },                                                         
                                    lastName: { type: "string" }
                                    }                               
                                });
                                break;
    
    case 'Address':
    mydatamodel = kendo.data.Model.define({
                                    id: "__KEY",
                                    fields: {
                                    __KEY: { type: "string" },
                                    __STAMP: { type: "number" },
                                    ID: { editable: false, nullable: true },                                                                
                                    street: { type: "string" }
                                    }                               
                                });
                                break;
    case 'ContactType':     
    mydatamodel = kendo.data.Model.define({
                                    id: "__KEY",
                                    fields: {
                                    __KEY: { type: "string" },
                                    __STAMP: { type: "number" },
                                    ID: { editable: false, nullable: true },                                                                
                                    name: { type: "string" }                                
                                    }                               
                                });
                                break;
    };
    
    return new mydatamodel();
    };
    

    And use your creator function like this:

    var mymodel = GetModel("Contact");
    

    EDIT

    Or use you code like this:

    var mymodel = new (GetModel("Contact"))();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function that uses out parameters to return multiple values to the
I currently have a Javascript function that uses a string to reference an object
I have a function that uses Pattern#compile and a Matcher to search a list
I have a function that uses CDO to send emails with request to have
I have a function that uses the SharePoint api so the method SPUtility.GetLocalizedString is
I have a function that uses the Google Blobstore API, and here's a degenerate
I have written a javascript function that uses setInterval to manipulate a string every
I have a static logging function that uses StringBuilder to concatenate a bunch of
I have a function that is used to creating a directory. It uses CreateDirectoryA()
I have code that uses Win API function RegSaveKeyEx to save registry entries to

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.