Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var obj = {
- a: 1,
- print() {
- console.log(this.a);
- }
- }
- obj.print(); // 1
- var fn = obj.print
- window.fn(); // undefined
- ===
- function ctx() {
- this.somePropery = 1;
- console.log(this.somePropery); // 1
- }
- ctx();
- ===
- for (var i = 1; i < 10; i++) {
- setTimeout(() => console.log(i), 10); //
- }
- ===
- var obj = {
- a: 1
- };
- (function(obj) {
- ----------------------
- // obj.a = 2;
- obj = {
- a: 2
- };
- --------------------------
- })(obj);
- console.log(obj.a); // 1
- ===
- var foo = 1;
- function bar() {
- alert(foo); // 1
- if (!foo) {
- var foo = 10;
- }
- alert(foo); // 10
- }
- alert(foo); // 1
- bar();
- ===
- (function() {
- f(); // 1
- f = function() {
- console.log(1);
- }
- })()
- function f() {
- console.log(2);
- }
- f(); // 2
- ===
- const p1 = Promise.resolve(2);
- const p2 = Promise.reject(3);
- const p3 = Promise.resolve(4);
- ------------------------------------
- const promises = [p1, p2, p3];
- promises.map((item)=> item.catch(error)=>Promise.resolve(3));
- ------------------------------------
- Promise.all(promises)
- .then((results) => console.log(results));
- ===
- setTimeout(() => console.log('log'), 10000);
- ===
- function sum() {
- };
- // Вызов sum с пустым аргументом должен вернуть сумму предыдущих вызовов
- sum(1)(2)(3)() // => 6
- function debounce(func, wait) {
- };
- const fn = debounced(() = console.log('LOG!'), 300);
- fn();
- fn();
- fn(); // 'LOG!'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement