var getAdder = function () { var res = 0; return function(x) { res += x; return res; } };
var sum = getAdder();
sum(1); // 1
sum(3); // 4
var sum2 = getAdder(); // два независимых сумматора
sum2(1); //1
sum2(3); // 4
var adder2 = new Function('x', 'var result = adder.last? adder.last + x : x; adder.last = result; return result');
adder2(2); //ReferenceError: adder is not defined
var a = [ { id: 0 }, { id: 1 }, { id: 2 } ];
for(var i = 0; i != a.length; ++i)
{
var el = a[i];
setTimeout(function() {
console.log('timeout',el);
},100);
}
timeout Object { id: 2 }
timeout Object { id: 2 }
timeout Object { id: 2 }
var a = [ { id: 0 }, { id: 1 }, { id: 2 } ];
var createCB = function(e){
return function() {
console.log('timeout',e);
};
};
for(var i = 0; i != a.length; ++i)
{
var el = a[i];
setTimeout(createCB(el),100);
}
timeout Object { id: 0 }
timeout Object { id: 1 }
timeout Object { id: 2 }
scope.$parent
div.food_box_scroll_item > div.btn_food_box_scroll > a.but_call_min
$('.but_call_min').click(function(){
console.log('Selected:',$(this).closest('.food_box_scroll_item').find(".value_number_of_servings").val());
});
/*Add to cart*/
$(document).ready(function() {
$(".food_box_scroll_item .btn_food_box_scroll .but_call_min").click(function(){
prod_id = $(this).attr("rel");
count_this = parseInt($(this).closest('.food_box_scroll_item').find(".value_number_of_servings").val());
// addToCart(prod_id, count_this);
// alert(count_this); // - так плохо
console.log(count_this); // - так хорошо
});
});
<Directory "%ssitedir%/*">
AllowOverride All
Options -MultiViews +Indexes +FollowSymLinks +IncludesNoExec +Includes +ExecCGI
<LimitExcept GET POST HEAD >
Require all denied
</LimitExcept>
</Directory>
<Directory "%ssitedir%/*">
AllowOverride All
Options -MultiViews +Indexes +FollowSymLinks +IncludesNoExec +Includes +ExecCGI
<LimitExcept GET POST HEAD OPTIONS DELETE>
Require all denied
</LimitExcept>
</Directory>
Order.query({id: 'all'}, function(orders) {
$scope.orders = orders;
console.log('get data from server');
$scope.$broadcast('dataloaded');
});
.directive('orderDrct', ['$compile',
function ($compile) {
return {
restrict: 'A',
link: function (scope, element) {
scope.$on('dataloaded', function ()
{
// Ваш код
console.log('end of directive');
});
}
};
}
]);