我在我的项目中得到了这段代码,但我对它不满意,因为重复了相同的 var 声明。有没有更好的方法来处理它?
if (type == 1) {
var addressId = data.address.BillingAddress.id;
var addressTitle = data.address.BillingAddress.title;
var $select = $('.billingAddressId');
var $notification = $('.billingNotification');
} else {
var addressId = data.address.DeliveryAddress.id;
var addressTitle= data.address.DeliveryAddress.title;
var $select = $('.deliveryAddressId');
var $notification = $('.shippingNotification');
}