Skip to content Skip to sidebar Skip to footer

How To Create Javascript Object Using Iife

I have a Student object like the following, function Student(){ this.studentName = ''; } Student.prototype.setStudentName=function(studentName){ this.studentName = stud

Solution 1:

To make Student available outside the IIFE, return it and assign it to a global variable:

var Student = (function(){

    function Student(){
      this.studentName = "";
    }

    /* more code */

    return Student;
})();

Post a Comment for "How To Create Javascript Object Using Iife"