Skip to main content
deleted 180 characters in body
Source Link
brasofilo
  • 26.2k
  • 15
  • 96
  • 188

I am working in JavaScript where I need to check the instanceof a custom JavaScript object & if the instance of that object is customTypeA then I need perform certain functions, where as in all other cases, we need to perform some different set of logic.

More detailed scenario:

IWe have a generic form submit button which gets included on all form pages. Now we have a common JavaScript for form submit and specific JavaScript files for each form pages. Each of these specific JavaScript files create an object with name of commonObjectName. Where on form submit JavaScript calls validate & submit on commonObjectName, which will in turn invoke validate & submit for the respective JavaScript instance.

Now, when I need to perform certain checks between validate & submit actions for form A, where as they are not needed for form B, so I wrote below code in formSubmit.js

var commonObjInstanceOfFormA = commonObjectName instanceof FormAJavascript;
if(commonObjInstanceOffFormA) {
    //do something
} else {
   //do something else
}

Now, the problem occurs when I am on Form B. FormAJavascript type gives a reference error since it is not included on form B at all.

Is there a way to find the type of contructor of commonObjectNamecommonObjectName in a string format or find the instance of the object in efficient way so that I can perform a different set of logic for type A & different for Type B?

Apologize for non-readibility or any other problems, since this is my first question on StackOverflow. Please, let me know if you need any more details. I will be happy to share it.

I am working in JavaScript where I need to check the instanceof a custom JavaScript object & if the instance of that object is customTypeA then I need perform certain functions, where as in all other cases, we need to perform some different set of logic.

More detailed scenario:

I have a generic form submit button which gets included on all form pages. Now we have a common JavaScript for form submit and specific JavaScript files for each form pages. Each of these specific JavaScript files create an object with name of commonObjectName. Where on form submit JavaScript calls validate & submit on commonObjectName, which will in turn invoke validate & submit for the respective JavaScript instance.

Now, when I need to perform certain checks between validate & submit actions for form A, where as they are not needed for form B, so I wrote below code in formSubmit.js

var commonObjInstanceOfFormA = commonObjectName instanceof FormAJavascript;
if(commonObjInstanceOffFormA) {
    //do something
} else {
   //do something else
}

Now, the problem occurs when I am on Form B. FormAJavascript type gives a reference error since it is not included on form B at all.

Is there a way to find the type of contructor of commonObjectName in a string format or find the instance of the object in efficient way so that I can perform a different set of logic for type A & different for Type B?

Apologize for non-readibility or any other problems, since this is my first question on StackOverflow. Please, let me know if you need any more details. I will be happy to share it.

I am working in JavaScript where I need to check the instanceof a custom JavaScript object & if the instance of that object is customTypeA then I need perform certain functions, where as in all other cases, we need to perform some different set of logic.

More detailed scenario:

We have generic form submit button which gets included on all form pages. Now we have a common JavaScript for form submit and specific JavaScript files for each form pages. Each of these specific JavaScript files create an object with name of commonObjectName. Where on form submit JavaScript calls validate & submit on commonObjectName, which will in turn invoke validate & submit for the respective JavaScript instance.

Now, when I need to perform certain checks between validate & submit actions for form A, where as they are not needed for form B, so I wrote below code in formSubmit.js

var commonObjInstanceOfFormA = commonObjectName instanceof FormAJavascript;
if(commonObjInstanceOffFormA) {
    //do something
} else {
   //do something else
}

Now, the problem occurs when I am on Form B. FormAJavascript type gives a reference error since it is not included on form B at all.

Is there a way to find the type of contructor of commonObjectName in a string format or find the instance of the object in efficient way so that I can perform a different set of logic for type A & different for Type B?

I am working on a javascriptin JavaScript where I need to check instanceofthe instanceof a custom javascriptJavaScript object & if the instance of that object is customTypeA then I need perform certain functions, where as in all other cases, we need to perform some different set of logic. More detailed scenario - We

More detailed scenario:

I have a generic form submit button which gets included on all form pages. Now we have a common javascriptJavaScript for form Submit &submit and specific javascriptJavaScript files for each form pages. Each of these specific javascriptJavaScript files create an object with name of commonObjectNamecommonObjectName. Where ason form submit javascriptJavaScript calls validate & submit on commonObjectNamecommonObjectName, which will inturnin turn invoke validate & submit for the respective javascriptJavaScript instance. Now

Now, when I need to perform certain checks between validate & submit actions for form A, where as they are not needed for form B, so I wrote below code in formSubmit.js

var commonObjInstanceOfFormA = commonObjectName instanceof FormAJavascript;
if(commonObjInstanceOffFormA) {
    //do something
} else {
   //do something else
}

Now, the problem occurs when I am on Form B. FormAJavascriptFormAJavascript type gives a reference error since it is not included on form B at all.

Is there a way to find the type of contructor of commonObjectName in a string format or find the instance of the object in efficient way so that I can perform a different set of logic for type A & different for Type B?

Apologize for non-readibility or any other problems, since this is my first question on StackOverflow. Please, let me know if you need any more details. WillI will be happy to share it.

I am working on a javascript where I need to check instanceof a custom javascript object & if instance of that object is customTypeA then I need perform certain functions, where as in all other cases, we need to perform some different set of logic. More detailed scenario - We have generic form submit button which gets included on all form pages. Now we have a common javascript for form Submit & specific javascript files for each form pages. Each of these specific javascript files create an object with name of commonObjectName. Where as form submit javascript calls validate & submit on commonObjectName, which will inturn invoke validate & submit for respective javascript instance. Now, when I need to perform certain checks between validate & submit actions for form A, where as they are not needed for form B, so I wrote below code in formSubmit.js

var commonObjInstanceOfFormA = commonObjectName instanceof FormAJavascript;
if(commonObjInstanceOffFormA) {
    //do something
} else {
   //do something else
}

Now, problem occurs when am on Form B. FormAJavascript type gives reference error since it is not included on form B at all.

Is there a way to find type of contructor of commonObjectName in a string format or find instance of object in efficient way so that I can perform different set of logic for type A & different for Type B?

Apologize for non-readibility or any other problems, since this is my first question on StackOverflow. Please, let me know if you need any more details. Will be happy to share it.

I am working in JavaScript where I need to check the instanceof a custom JavaScript object & if the instance of that object is customTypeA then I need perform certain functions, where as in all other cases, we need to perform some different set of logic.

More detailed scenario:

I have a generic form submit button which gets included on all form pages. Now we have a common JavaScript for form submit and specific JavaScript files for each form pages. Each of these specific JavaScript files create an object with name of commonObjectName. Where on form submit JavaScript calls validate & submit on commonObjectName, which will in turn invoke validate & submit for the respective JavaScript instance.

Now, when I need to perform certain checks between validate & submit actions for form A, where as they are not needed for form B, so I wrote below code in formSubmit.js

var commonObjInstanceOfFormA = commonObjectName instanceof FormAJavascript;
if(commonObjInstanceOffFormA) {
    //do something
} else {
   //do something else
}

Now, the problem occurs when I am on Form B. FormAJavascript type gives a reference error since it is not included on form B at all.

Is there a way to find the type of contructor of commonObjectName in a string format or find the instance of the object in efficient way so that I can perform a different set of logic for type A & different for Type B?

Apologize for non-readibility or any other problems, since this is my first question on StackOverflow. Please, let me know if you need any more details. I will be happy to share it.

Source Link

How to get javascript object type in a string format?

I am working on a javascript where I need to check instanceof a custom javascript object & if instance of that object is customTypeA then I need perform certain functions, where as in all other cases, we need to perform some different set of logic. More detailed scenario - We have generic form submit button which gets included on all form pages. Now we have a common javascript for form Submit & specific javascript files for each form pages. Each of these specific javascript files create an object with name of commonObjectName. Where as form submit javascript calls validate & submit on commonObjectName, which will inturn invoke validate & submit for respective javascript instance. Now, when I need to perform certain checks between validate & submit actions for form A, where as they are not needed for form B, so I wrote below code in formSubmit.js

var commonObjInstanceOfFormA = commonObjectName instanceof FormAJavascript;
if(commonObjInstanceOffFormA) {
    //do something
} else {
   //do something else
}

Now, problem occurs when am on Form B. FormAJavascript type gives reference error since it is not included on form B at all.

Is there a way to find type of contructor of commonObjectName in a string format or find instance of object in efficient way so that I can perform different set of logic for type A & different for Type B?

Apologize for non-readibility or any other problems, since this is my first question on StackOverflow. Please, let me know if you need any more details. Will be happy to share it.