Web Analytics Made Easy -
StatCounter Cloning object and I can't override properties, why? - CodingForum

Announcement

Collapse
No announcement yet.

Cloning object and I can't override properties, why?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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?

  • #2
    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
    Last edited by Old Pedant; Aug 24, 2011, 10:35 PM.
    Be yourself. No one else is as qualified.

    Comment


    • #3
      But cloneNode() only works on DOM objects. At least that's what all the docs say.
      Be yourself. No one else is as qualified.

      Comment

      Working...
      X