var v1 = {
a: ''value for a'',
b:''value for b''
}
var v2 = {
c: ''value for c'',
d: function(){some code...}
};
var v3 = v2.merge(v1);
I''m getting an error doing this...
what is wrong?
try it this way:
var v1 = { a: ''value for a'', b:''value for b''
};
var v2 = { c: ''value for c'', d: function(){} };
var v3 = $H(v2).merge($H(v1));
v3.inspect();
// #<Hash:{''c'': ''value for c'',
''a'': ''value for a'', ''b'':
''value for b''}>
but v2.d will be ignored (type of the value is function)
hth
sigi
On 7/10/06, Fernando <fernando-YZKC1iyWIStfJ/NunPodnw@public.gmane.org>
wrote:>
> var v1 = {
> a: ''value for a'',
> b:''value for b''
> }
>
> var v2 = {
> c: ''value for c'',
> d: function(){some code...}
> };
>
> var v3 = v2.merge(v1);
> I''m getting an error doing this...
>
> what is wrong?
> _______________________________________________
> Rails-spinoffs mailing list
> Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
>
--
Mit freundlichen Grüßen
Siegfried Puchbauer
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Is it easy to explain the difference between a hash
var myHash = {a: ''value for a''}
and an object
var myObject = {a: ''value for a''}
Sam
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Sam wrote:> Is it easy to explain the difference between a hash > > var myHash = {a: ''value for a''} > > and an object > > var myObject = {a: ''value for a''}There is no difference between those. They are both associative arrays (hashes). -- Michael Peters Developer Plus Three, LP
"but v2.d will be ignored (type of the value is function)"
ok, but so how to do this :
I have Default Options for all my Ajax.Updater()
DefaultOptions = {
asynchronous:true,
evalScripts:true,
onLoaded:function(request){Element.hide(''spinner'')},
onLoading:function(request){Element.show(''spinner'')}
}
I have lots of Ajax.Updater()
var MyPageFunctions = {
func1 : function() {
var OptionForThisFunction = {onComplete: function() { some code
} };
//I would like that {options} be OptionForThisFunction + Default
Options
new Ajax.Updater(''bla'',''url'',
{options});
},
func2 : function() {
var OptionForThisFunction = {onComplete: function() { some other
code } };
//I would like that {options} be OptionForThisFunction + Default
Options
new Ajax.Updater(''bla2'',''url'',
{options} );
}
. . .
}
there is a way to do this?
tks
Siegfried Puchbauer escreveu:
try it this way:
var v1 = { a:
''value for a'', b:''value for b'' };
var v2 = { c:
''value for c'', d: function(){} };
var v3 $H(v2).merge($H(v1));
v3.inspect();
//
#
but v2.d will be ignored (type of the value is function)
hth
sigi
On 7/10/06, Fernando <
fernando-YZKC1iyWIStfJ/NunPodnw@public.gmane.org> wrote:
var
v1 = {
a: ''value for a'',
b:''value for b''
}
var v2 = {
c: ''value for c'',
d: function(){some code...}
};
var v3 = v2.merge(v1);
I''m getting an error doing this...
what is wrong?
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
--
Mit freundlichen Grüßen
Siegfried Puchbauer
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
When he said ignored, I think he only meant for the inspect function (which
doesn't print d even though it exists).
The functions will still be merged together into v3 since the $H() function
doesn't discriminate by type AFAIK.
-----Original Message-----
From: rails-spinoffs-bounces@lists.rubyonrails.org
[mailto:rails-spinoffs-bounces@lists.rubyonrails.org]On Behalf Of Fernando
Sent: Monday, July 10, 2006 10:03 AM
To: rails-spinoffs@lists.rubyonrails.org
Subject: Re: [Rails-spinoffs] prototype hash method
"but v2.d will be ignored (type of the value is function)"
ok, but so how to do this :
I have Default Options for all my Ajax.Updater()
DefaultOptions = {
asynchronous:true,
evalScripts:true,
onLoaded:function(request){Element.hide('spinner')},
onLoading:function(request){Element.show('spinner')}
}
I have lots of Ajax.Updater()
var MyPageFunctions = {
func1 : function() {
var OptionForThisFunction = {onComplete: function() { some code } };
//I would like that {options} be OptionForThisFunction + Default Options
new Ajax.Updater('bla','url', {options});
},
func2 : function() {
var OptionForThisFunction = {onComplete: function() { some other code }
};
//I would like that {options} be OptionForThisFunction + Default Options
new Ajax.Updater('bla2','url', {options} );
}
. . .
}
there is a way to do this?
tks
Siegfried Puchbauer escreveu:
try it this way:
var v1 = { a: 'value for a', b:'value for b' };
var v2 = { c: 'value for c', d: function(){} };
var v3 = $H(v2).merge($H(v1));
v3.inspect();
// #<Hash:{'c': 'value for c', 'a': 'value for
a', 'b': 'value for b'}>
but v2.d will be ignored (type of the value is function)
hth
sigi
On 7/10/06, Fernando < fernando@setti.com.br> wrote:
var v1 = {
a: 'value for a',
b:'value for b'
}
var v2 = {
c: 'value for c',
d: function(){some code...}
};
var v3 = v2.merge(v1);
I'm getting an error doing this...
what is wrong?
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
--
Mit freundlichen Grüßen
Siegfried Puchbauer
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Hi Fernando,
why don''t you just use Object.extend:
var v1 = {
a: ''value for a'',
b:''value for b''
};
var v2 = {
c: ''value for c'',
d: function(){some code...}
};
var v3 = Object.extend(v1, v2);
This will preserve your function.
regards,
Tobie
On 10 juil. 2006, at 16:03,
rails-spinoffs-request-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org wrote:
> From: "Siegfried Puchbauer"
<siegfried.puchbauer-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> Subject: Re: [Rails-spinoffs] prototype hash method
> To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> Message-ID:
>
<53239a200607100536v6a00c497s228b1c325350a6bd-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
> Content-Type: text/plain; charset="iso-8859-1"
>
> try it this way:
>
> var v1 = { a: ''value for a'', b:''value for
b'' };
> var v2 = { c: ''value for c'', d: function(){} };
> var v3 = $H(v2).merge($H(v1));
>
> v3.inspect();
> // #<Hash:{''c'': ''value for c'',
''a'': ''value for a'', ''b'':
''value for b''}>
>
> but v2.d will be ignored (type of the value is function)
>
> hth
>
> sigi
>
> On 7/10/06, Fernando
<fernando-YZKC1iyWIStfJ/NunPodnw@public.gmane.org> wrote:
>>
>> var v1 = {
>> a: ''value for a'',
>> b:''value for b''
>> }
>>
>> var v2 = {
>> c: ''value for c'',
>> d: function(){some code...}
>> };
>>
>> var v3 = v2.merge(v1);
>> I''m getting an error doing this...
>>
>> what is wrong?
>> _______________________________________________
>> Rails-spinoffs mailing list
>> Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
>> http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
>>
>
tks Tobie, I''m new to javascript and prototype framework, I will use Object.extend: tks Tobie Langel escreveu:> Hi Fernando, > > why don''t you just use Object.extend: > > var v1 = { > a: ''value for a'', > b:''value for b'' > }; > > var v2 = { > c: ''value for c'', > d: function(){some code...} > }; > > var v3 = Object.extend(v1, v2); > > This will preserve your function. > > regards, > > Tobie > > On 10 juil. 2006, at 16:03, > rails-spinoffs-request-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org wrote: > >> From: "Siegfried Puchbauer" <siegfried.puchbauer-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >> Subject: Re: [Rails-spinoffs] prototype hash method >> To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> Message-ID: >> <53239a200607100536v6a00c497s228b1c325350a6bd-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> >> Content-Type: text/plain; charset="iso-8859-1" >> >> try it this way: >> >> var v1 = { a: ''value for a'', b:''value for b'' }; >> var v2 = { c: ''value for c'', d: function(){} }; >> var v3 = $H(v2).merge($H(v1)); >> >> v3.inspect(); >> // #<Hash:{''c'': ''value for c'', ''a'': ''value for a'', ''b'': ''value for b''}> >> >> but v2.d will be ignored (type of the value is function) >> >> hth >> >> sigi >> >> On 7/10/06, Fernando <fernando-YZKC1iyWIStfJ/NunPodnw@public.gmane.org> wrote: >>> >>> var v1 = { >>> a: ''value for a'', >>> b:''value for b'' >>> } >>> >>> var v2 = { >>> c: ''value for c'', >>> d: function(){some code...} >>> }; >>> >>> var v3 = v2.merge(v1); >>> I''m getting an error doing this... >>> >>> what is wrong? >>> _______________________________________________ >>> Rails-spinoffs mailing list >>> Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>> http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >>> >> > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Actually, Fernando,
I must have been thinking slowly...
Using Object.extend like that will also extend v1 to contain v2, which
is probably not what you wanted...
this would do the trick:
var v3 = {};
Object.extend(v3, v2);
Object.extend(v3, v1);
If you just wanted to add v2 to v1:
Object.extend(v1, v2);
Hope this clarifies a bit.
Regards,
Tobie
On 10 juil. 2006, at 16:15, Tobie Langel wrote:
> Hi Fernando,
>
> why don''t you just use Object.extend:
>
> var v1 = {
> a: ''value for a'',
> b:''value for b''
> };
>
> var v2 = {
> c: ''value for c'',
> d: function(){some code...}
> };
>
> var v3 = Object.extend(v1, v2);
>
> This will preserve your function.
>
> regards,
>
> Tobie
>
> On 10 juil. 2006, at 16:03,
> rails-spinoffs-request-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
wrote:
>
>> From: "Siegfried Puchbauer"
<siegfried.puchbauer-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
>> Subject: Re: [Rails-spinoffs] prototype hash method
>> To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
>> Message-ID:
>>
<53239a200607100536v6a00c497s228b1c325350a6bd-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
>> Content-Type: text/plain; charset="iso-8859-1"
>>
>> try it this way:
>>
>> var v1 = { a: ''value for a'', b:''value for
b'' };
>> var v2 = { c: ''value for c'', d: function(){} };
>> var v3 = $H(v2).merge($H(v1));
>>
>> v3.inspect();
>> // #<Hash:{''c'': ''value for c'',
''a'': ''value for a'', ''b'':
''value for
>> b''}>
>>
>> but v2.d will be ignored (type of the value is function)
>>
>> hth
>>
>> sigi
>>
>> On 7/10/06, Fernando
<fernando-YZKC1iyWIStfJ/NunPodnw@public.gmane.org> wrote:
>>>
>>> var v1 = {
>>> a: ''value for a'',
>>> b:''value for b''
>>> }
>>>
>>> var v2 = {
>>> c: ''value for c'',
>>> d: function(){some code...}
>>> };
>>>
>>> var v3 = v2.merge(v1);
>>> I''m getting an error doing this...
>>>
>>> what is wrong?
>>> _______________________________________________
>>> Rails-spinoffs mailing list
>>> Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
>>> http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
>>>
>>
>
Sam wrote:> Is it easy to explain the difference between a hash > > var myHash = {a: ''value for a''} > > and an object > > var myObject = {a: ''value for a''}There is no difference between those. They are both associative arrays (hashes). --------------------------------------------------- Since prototype.js has Object and Hash methods, maybe my question should have been something like: "What is the reasoning behind why prototype offers different properties and methods for Hash and Object types?" Sam
Here it is as a one-liner that I use often to merge a set of options with a
default:
options = Object.extend(Object.extend({}, _defaultOptions), options);
_defaultOptions = your defaults
options = passed in options and then the merged options
Brandon
On 7/10/06, Sam <sam.google-Uc2IQQBAS6sAvxtiuMwx3w@public.gmane.org>
wrote:>
> Sam wrote:
> > Is it easy to explain the difference between a hash
> >
> > var myHash = {a: ''value for a''}
> >
> > and an object
> >
> > var myObject = {a: ''value for a''}
>
> There is no difference between those. They are both associative arrays
> (hashes).
> ---------------------------------------------------
>
> Since prototype.js has Object and Hash methods, maybe my question should
> have been something like: "What is the reasoning behind why prototype
> offers different properties and methods for Hash and Object types?"
>
> Sam
>
>
>
>
>
> _______________________________________________
> Rails-spinoffs mailing list
> Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
>
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
The Hash that prototype declares provides associative array functionality, like
returning of keys and values, stuff that Object doesn''t provide on
it''s own. It''s intent is to act like an associative array,
where Object is intended to be used as an Object.
Contrary to my previous understanding, the Hash functions do not handle values
with type function. They still get copied around, but aren''t visible
from any of the hash functions like values() or keys().
My apologies for any confusion I may have caused out there.
Cheers
P.S: If what I''ve said has confused you, try this example and see for
yourself.
var h1 = { a: 1, b: 2 };
var h2 = { c: 3, d: function() { alert(''d exists''); } };
var mergedHsh = $H(h1).merge(h2);
mergedHsh.d();
alert(mergedHsh.inspect());
-----Original Message-----
From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
[mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org]On
Behalf Of Sam
Sent: Monday, July 10, 2006 10:51 AM
To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
Subject: RE: [Rails-spinoffs] prototype hash method
Sam wrote:> Is it easy to explain the difference between a hash
>
> var myHash = {a: ''value for a''}
>
> and an object
>
> var myObject = {a: ''value for a''}
There is no difference between those. They are both associative arrays
(hashes).
---------------------------------------------------
Since prototype.js has Object and Hash methods, maybe my question should
have been something like: "What is the reasoning behind why prototype
offers different properties and methods for Hash and Object types?"
Sam
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs