I am trying to make a Chess Board. I have managed to load all the images into an image array. So that I don't have to repeatedly request the server for the images. (You would say browser cache would manage that,(if at all it will) but lets assume, it won't)
So the problem I face now is that each image that has to be repeated for example: the pawns, the blank spaces, rooks and knights, after adding to a table cell, and then re-adding to another table cell, doesn't give me two pawns. But only one. I guess that is because it is a single image object.
So I thought I'd clone the image object every time I have to use it. So what are the different ways to clone it.
I haven't use jQuery at all, ever. So I tried including this code in my script
function cloneBlank(blank,c) {
var img = jQuery.extend({},blank[c]);
return img;
}
Error: Uncaught ReferenceError: jQuery is not defined
(Read about the exted method here :Cloning a JavaScript object?)
I have also read about the .clone()
method, but have no idea how it is used
Moreover, does any of these methods ensure that the images would not be re-requested from the server and just copied as objects in memory (Else what is the point of having a image buffer).
Secondly Are there any methods that do ensure such behaviour.