Depth-first search (DFS) is an algorithm for traversing or searching tree or graph data structures. One starts at the root (selecting some arbitrary node as the root in the case of a graph) and explores as far as possible along each branch before backtracking.
https://en.wikipedia.org/wiki/Depth-first_search
Thursday, April 7, 2016
JAVASCRIPT - difference between call and apply functions
CALL
https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Function/call
APPLY
https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Function/apply
Its functions almost similar.
Its fundamental difference is that call() receive in its parameters a LIST of arguments, but apply() - single array of arguments.
Примечание: хотя синтаксис этой функции практически полностью идентичен функции
https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Function/call
APPLY
https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Function/apply
Its functions almost similar.
Its fundamental difference is that call() receive in its parameters a LIST of arguments, but apply() - single array of arguments.
Примечание: хотя синтаксис этой функции практически полностью идентичен функции
apply()
, фундаментальное различие между ними заключается в том, что функция call()
принимает список аргументов, в то время, как функция apply()
- одиночный массив аргументов.
JAVASCRIPT - the use of bind method of Function.prototype.bind()
https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Function/bind
Method bind() will bind the scope of the object's (passed as parameter) this to the function on which it was called.
Method bind() will bind the scope of the object's (passed as parameter) this to the function on which it was called.
this.x = 9;
var module = {
x: 81,
getX: function() { return this.x; }
};
module.getX(); // 81
var getX = module.getX;
getX(); // 9, поскольку в этом случае this ссылается на глобальный объект
// создаём новую функцию с this, привязанным к module
var boundGetX = getX.bind(module);
boundGetX(); // 81
function list() {
return Array.prototype.slice.call(arguments);
}
var list1 = list(1, 2, 3); // [1, 2, 3]
// Создаём функцию с предустановленным ведущим аргументом
var leadingThirtysevenList = list.bind(undefined, 37);
var list2 = leadingThirtysevenList(); // [37]
var list3 = leadingThirtysevenList(1, 2, 3); // [37, 1, 2, 3]
Subscribe to:
Posts (Atom)