Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-25-2011, 01:40 AM   PM User | #1
BrightNail
Regular Coder

 
Join Date: Jun 2002
Posts: 349
Thanks: 2
Thanked 0 Times in 0 Posts
BrightNail is an unknown quantity at this point
Cloning object and I can't override properties, why?

I have something like this

var oneTest = new CustomObj({
prop1 : 'value1',
prop2 : 'value2',
prop3 : 'value3'
})

var twoText = Object.clone(oneTest)
twoText.prop2 = "newvalue2"


And when I console log twoText I see something like

+Data
prop2

Inside Data is a prop2 that has the value of "value2". THAT is the one I want to change/override... yet the console shows me that the prop2 is outside of the data structure so when I am acting on the cloned obj I am not getting the results i need.

I tried obj.extend etc.... and that didn't work, perhaps my syntax was wrong. Any advice?
BrightNail is offline   Reply With Quote
Old 08-25-2011, 02:33 AM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,578
Thanks: 62
Thanked 4,062 Times in 4,031 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Ummm...clone() is *NOT* a part of the standard JavaScript language.

It exists in jQuery, but there it can only clone DOM objects. (And the standard DOM has a cloneNode method which I'll bet is used internally by jQuery's clone() method.)

Look here:
http://stackoverflow.com/questions/1...ascript-object
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.

Last edited by Old Pedant; 08-25-2011 at 02:35 AM..
Old Pedant is online now   Reply With Quote
Old 08-25-2011, 02:43 AM   PM User | #3
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,578
Thanks: 62
Thanked 4,062 Times in 4,031 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
But cloneNode() only works on DOM objects. At least that's what all the docs say.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is online now   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:16 AM.


Advertisement
Log in to turn off these ads.