I'm not sure if I'm using the right terminology as I'm fairly new to Object Oriented Programming. I can make "traditional objects" in the following way:
(New File: Person.js)
function Person() {
this.name;
this.getName = function getName(){
return this.name;
}
this.setName = function setName(name){
this.name = name;
}
}
And then to use it in the main file I have to type:
var myFriend = new Person();
myFriend.setName("Bob");
in order to use it. You have to create an instance of the object to use its functions.
What I want to create is something I believe is called a "static object" at least in Java or perhaps a libary. I'm thinking of something similar to use the built in Math functions. I can type
Math.sin(3.14);
without having to do something like:
var myMath = new Math();
myMath.sin(3.14);
Effectively, I want a library, but I don't know how to set it up
(File: mathlib.js)
//mathlib.js
function mathlib() {
this.printStuff = function printStuff(){
alert("mathlib print");
}
}
and then in the main file:
mathlib.printStuff();
This gives an error of: TypeError: mathlib.printStuff is not a function
Not sure of where I'm going wrong.. (I am including the file, in the same way as before)