i'm currently creating a tracker as a proof-of-concept. before the
tracker is started, events to be hooked are registered. when the
tracker starts, a timer is started and events are tracked by "frame"
which, by default, is 1 second in length. all hooked events occurring
within the "frame" are saved for reference.

my problem lies in copying the events as they happen. we all know that
objects are passed by reference, so i'm trying to clone the event
object so i can reference that event later on (think: playback).

i've been unsuccessful using jQuery.extend({}, e) or other clone
functions floating around on the internet. i still get a reference to
the last event that occurred as opposed to an event in the past.

example:

var _events = new Array();

function saveEvent(e) {
    _events[_events.length] = jQuery.extend({}, e);
}

$('input[type=text]').bind('keyup', saveEvent);

in this case, all entries in the _events array will be the same. the
main thing i'd be looking for with the keyup event is the value of the
textbox after the event occurred.

i've also used the following from Keith Devens' blog with the same
results:

function clone(obj){
    if(obj == null || typeof(obj) != 'object')
        return obj;
        console.log(obj);
    var temp = obj.constructor();
    for(var key in obj)
        temp[key] = clone(obj[key]);
    return temp;
}

Reply via email to