Reputation: 1521
I am trying to create playlist class object from Main class function.
function playlist(){
playlist.prototype.check = function (){
alert(2);
};
this.check();
};
Main = {};//literal class
Main.test = function(){
var obj = new playlist();
}
Why am I not able to get the alert?
Upvotes: 0
Views: 72
Reputation: 79
Ok my friend
There's a simple solution for this To do it, we need to create the class declaration, then we make a prototype playlist class.
In this example i prefer to use first-capitalize letter on naming class in JS.
// Playlist class declaration
function Playlist() {
// Class properties
// for example: this.songs = [];
// for example: this.startingIndex = 0;
}
// Adds extra behavior for Playlist class
Playlist.prototype.check = function () {
alert(2);
};
// Creates an instance from Playlist
var playlistObj = new Playlist();
// Calls check method.
playlistObj.check();
Upvotes: 1