I using JavaScript and wanted to ask maybe I’m not using exactly the right way. I have ‘classes’ for example:
function Games() {
this.a='';
.
.
}
and:
functios GamesTypes() {
this.b='';
.
.
}
for each class I declare object:
var games = new Games();
A lot of times after clicking on element I need to display on the next pages the game name for example, so when user clicks on a game I setting
Games.a="game55";
and next all pages reads it and display it:
var toDisplay = Games.a;
Is it the best thing to store some data that should be displayed in some pages?
You’re not doing bad, at least as i think.
Just consider in JavaScript it’s not necessary to creat a “class” or a constructor function for any type of pre-set object that you may need, just using the Object native object may save you some time declaring those constructor functions.
For example, if you need to create a new page called B that’s going to be similar to a previous one called A, and you’ve an object for A that haves all the properties and methods it needs, use
B = Object.create(A)to make a new object B that will inherit all the properties and methods from A, as A would be the prototype of B.A simple example
This way you don’t have to declare a constructor funciton for every type of page, just make objects inherit what they need if it’s already in another objects, and then add all the stuff to the new page. You can also override the properties that B inherited from A by just declaring them with their new value.