Hi guys
How can I better optimize my js object.. As you can see there is a lot of repeating and I want to find better way to write this object. I'm new to JS thats why so fool question. Thanks in advance.
//field odject
var $field = $("#field");
var field = {
width: $field.width(),
offsetTop: $field.offset().top,
offsetLeft: $field.offset().left,
offsetRight: $field.offset().left + $field.width(),
offsetBottom: $field.offset().top + $field.height()
};
function field($sel){
//field odject
var $field = $($sel);
var offset = $field.offset();
var field = {
width: $field.width(),
offsetTop:offset.top,
offsetLeft: offset.left,
offsetRight: offset.left + $field.width(),
offsetBottom: offset.top + $field.height()
};
return field;
}
You extend your functionality by creating a constructor and return the object from your function.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments