Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

extend or merge in jquery

Tags:

jquery

I have an object that has some default properties in it. I want to override those properties if options have been passed to my method.

    myMethod: function(options){        
           var myObj = {
         prop1: _this.get('data1'),
         prop2: _this.get('data3'),
         prop3: _this.get('data4'),
       };

       if(options){
         $.extend( myObj, options );
      }
    }

When I do a log on myObj after the $extend is called its not showing the new data that was passed in via options

myMethod({prop1:"newData1", prop2:"newData2", prop3:"newData3"})
like image 434
Chapsterj Avatar asked Nov 14 '22 15:11

Chapsterj


1 Answers

Andrew Whitaker answered this in his comment above, it seems, with this jsfiddle:

http://jsfiddle.net/EWeTt/

like image 90
Shawn Avatar answered Jan 09 '23 03:01

Shawn