I'm learning how to make a Javascript plugin to make a modal window appear. I'm trying to learn using this codepen. When I try to test it somewhere else, I get the following error when the page loads:
Uncaught TypeError: Cannot set property 'raModal' of undefined
at raDialog.js:5 at raDialog.js:158
Looking at line 5, I can see that the error is referring to the start of the function that will construct the modal I want to display, but I don't quite understand why it's throwing an error on that line.
"use strict";
(function() {
// Make the constructor
this.raModal = function(){ //Line 5, error occurs here.
// Create global element references
this.closeButton = null;
this.modal = null;
this.overlay = null;
// Define option defaults
var defaults = {
autoOpen: false,
className: "",
closeButton: true,
content: "",
maxWidth: 500,
minWidth: 280,
minHeight: 150,
maxHeight: 700,
overlay: true,
onOK: "",
onClose: ""
};
// Create options by extending defaults with the passed in arugments
if (arguments[0] && typeof arguments[0] === "object") {
this.options = extendDefaults(defaults, arguments[0]);
}
if(this.options.autoOpen === true){
this.open();
}
};
//More code...
}()); //Line 158 also produces an error, might be related to Line 5's error.
I'm able to reproduce the error in a JSFiddle. Link to JSFiddle
Any explanations why this error is occurring is appreciated.