JQuery - Deep and Shallow copy
Shallow copy
var newObject = jQuery.extend({}, oldObject); |
Deep copy
var newObject = jQuery.extend(true, {}, oldObject); |
var simpleClass = { };
var simpleClass = { testAttribute : 'test', // atttribute testMethod : function() //method { return testAttribute; } };
var simpleClassObj = new simpleClass();
simpleClassObj.testAttriute;
simpleClassObj.testAttribute2 = 'test2';
<input type="text" name="test-name" id="test-id" class="test-class" style="test-style"/>
$('#test-id').val() // get value $('#test-id').attr('name') // get name $('test-id').html() //get inner HTML
var syndrome = {
doHide : function(){
this.hide('slow');
},
doShow : function(){
this.show( 'slow' );
},
doDisable : function(){
this.attr('disabled', 'disabled');
},
toggle : function(){
this.toggle();
},
getStyle : function(){
return this.attr('style');
},
setForeground : function(color){
var style = 'color:'+color+';';
this.attr('style', style+this.getStyle());
},
setBackground : function(color){
var style = 'background-color:'+color+';';
this.attr('style', style+this.getStyle());
},
getName : function(){
return this.attr('name');
},
getValue : function(){
return this.attr('value');
},
getClass : function() {
return this.attr('class');
},
getContent : function(){
return this.html();
}
};
var testObj = $('#test-id'); //get the dom object $.Extend( testObj, syndrome ); //extending the abstract class. So , the method should be available here. testObjtestObj.getValue(); // Get value testObj.getName(); // Get Name testObj.getContent(); // Get content