
Untitled
By: a guest on
Apr 30th, 2012 | syntax:
None | size: 0.93 KB | hits: 12 | expires: Never
Casting an object to a custom class
function Card(newId, newName, newDescription)
{
this.id = newId;
this.name = newName;
this.description = newDescription;
}
function HashTable()
{
var hashTableItems = {};
this.SetItem = function(key, value)
{
hashTableItems[key] = value;
}
this.GetItem = function(key)
{
return hashTableItems[key];
}
}
...
var card = new Card(id, name, description);
$.viacognitaspace.cards.SetItem(id, card);
...
var cardObject = $.viacognitaspace.cards.GetItem(cardNumber);
$('#cardName').text(cardObject.name);
$.viacognitaspace = {} /* define namespace if not already defined... */
var card = new Card(id, name, description);
/* the "new" keyword creats an instance of your HashTable function
which allows you to reference and modify it later on... */
$.viacognitaspace.cards = new HashTable();
$.viacognitaspace.cards.SetItem(id, card);