(function() {
f();
f = function() {
console.log(1);
}
})()
function f() {
console.log(2)
}
f();
function f()
, f
ReferenceError
, - , , f 1.< (function() {
f();
f = function() {
console.log(1);
}
})()
function f() {
console.log(2)
}
f();
> undefined
2
1
(function() {
var x = 1;
function x() {};
console.log(x);
})()
var
. function x() {};
, var x = 1
;var obj = {
a: 1
};
(function(obj) {
obj = {
a: 2
};
})(obj);
console.log(obj.a);
{a : 2}
, obj, .Logger = function(logFn) {
_logFn = logFn;
this.log = function(message) {
_logFn(new Date() + ": " + message);
}
}
var logger = new Logger(console.log);
logger.log("Hi!");
logger.log("Wazzup?");
TypeError: Illegal invocation
logger.log()
, — logger
.apply()
, .call()
, .bind()
< rightLogger = new Logger(console.log.bind(console))
> Logger {log: function}
< rightLogger.log("It's works")
> Sat Oct 04 2014 00:32:49 GMT+0400 (MSK): It's works
Source: https://habr.com/ru/post/239065/
All Articles