I have a javascript object named concept :
function concept() { this.ConceptId = 0; this.Name = ""; }
I am trying to run it in jQuery document.ready :
$(document).ready(function() { var concept = new concept; });
It returns an error:
Uncaught TypeError: concept is not a constructor
If I move an object inside document.ready , it works.
$(document).ready(function() { function concept() { this.ConceptId = 0; this.Name = ""; } var concept = new concept; });
I'm still new to javascript, as far as I understand document.ready gets started when the DOM is completed. I do not understand why it cannot access the object that is defined from the document.ready scope.
Here is the fiddle: https://jsfiddle.net/49rkcaud/1/
javascript jquery
londondev
source share