I think your problem is this:
* eval( this.name + ''Data'' ) // I assume
this.name+''Data'' turns into the ID of an input element that
should contain some data.
If this.name is myObjectName then the above becomes:
* eval( ''myObjectNameData'' )
Which when eval''ed returns an anonymous string value or possibly
nothing.
I believe you want eval( $(this.name+''Data'').value but that
will throw an error if the object doesn''t exist. You could throw a
try/catch around it, but that means you will have to do error catching
elsewhere.
-Andrew Martinez
-----Original Message-----
From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
[mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org]
On Behalf Of Jason Hummel
Sent: Wednesday, May 24, 2006 2:50 PM
To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
Subject: [Rails-spinoffs] newbie oo question
Hey everyone,
I''m trying to create an object that will have some properties
predefined, but will allow me to pass in properties to override those
standard props if needed. I''m trying something like:
var myObject = Class.create();
myObject.prototype = {
initialize: function(element, options) {
this.element = $(element);
this.name = this.element.id;
this.options = Object.extend({
data: eval(this.name + ''Data'')
}, options || {});
},
What I want is the this.options.data property to default to a JSON
object that has the convention of: id of element + ''Data'', so
if you
have this object in your javascript you don''t have to do anymore work.
If you want to pass in a different object though you can do so like:
new myObject(''elementID'',{data: myJSONObject})
It works great if no object is passed as an argument, but when I try
to pass a data param through nothing happens. I don''t even get an
error. I can pass other things through like:
new myObject(''elementID'',{foo: myJSONObject})
and I''ll be able to alert out myObject.options.foo, it''s only
when I''m
trying to override my default data property, I run into trouble.
Thanks for any help,
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs