xsnippet logotype

xsnippet

#363481, Untitled [ Text only ]

by Guest
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
Сделать так, чтобы заработало
console.log(object.a === 3) //true
delete object.a;
console.log(object.a === 1) //true

=========================
Сделать так, чтобы
object.myMethod() 
// Hey, I am in a parent
// Hey, I am in a child

Typescript аналог
class A {
	public myMethod() {
  	console.log('Hey, I am in a parent');
  }
}

class B extends A {
	public myMethod() {
    super.myMethod();
  	console.log('Hey, I am in a child');
  }
}
=========================
Реализовать функцию toBooleanArray, которая каждый элемент массива преобразовывает к соответствующему логическому значению
[1,0,-1, [0]].toBooleanArray(); //[true, false, true, true]
=========================
Реализовать Dependency Injection 

var multiplicator = {
 invoke: function() {
 		return this.a * this.b;
 }
}

var divider = {
	invoke: function() {
 		return this.a / this.b;
  }
}

var obj = new MyInjectable(3, 2, multiplicator);
var anotherObj = new MyInjectable(10, 5, divider);
console.log(obj.doCommand()); //6
console.log(anotherObj.doCommand()); //2
=========================
Написать Monkey Patch для getPrivate и getPublic
var module = (function() {
	var private = 1;
  return {
	public: 2,
  	getPrivate: function() {
			return private;
		},
    getPublic: function() {
      return this.public;
    }
  }
})();

//Magic

module.getPrivate();
//Private value is unreachable;
//Result of calculations is 1
//1

module.getPublic();
//Public value is 2
//Result of calculations is 2
//2
==========================
function FeedbackBox(elem, options) {
  this.options = options;  
  this.element = elem;  
  this.isOpen = false;
}

FeedbackBox.prototype.toggleError = function(obj, isError) {
  if(isError) {
    obj.class = "error";
  } else {
    obj.class = "OK";
  }
};

var obj = new FeedbackBox({}, {prop: 'noErrors'});
const object = {};
obj.toggleError(object, true);
console.log(obj.options.prop) //noErrors
MAGIC
obj.toggleError(object, true);
console.log(obj.options.prop) //hasError