www.rozumim.cz

What I've learned ~ 3

JavaScript

There is a big difference between for...of and for...in

What will print the following piece of code?

1
2
3
4
5
6
7
8
9
10
11
let abc = ['a', 'b', 'c'];

console.log('for...of');  
for(let i of abc) {
  console.log(i);  
}

console.log('for...in');  
for(let i in abc) {
  console.log(i);  
}

The for...of loop is using iterator, for...in loops over enumerable properties of an object.

What if we want to use for...of loop with an object then? Try it yourself.

What class is this object an instance of?

There is a constructor property that points to the function (or class) that was used to create that object. And we want its name.

1
2
3
4
class A { }

let a = new A();
console.log('a.constructor.name=' + a.constructor.name);

But what if we don’t call any function?

1
2
let o = {};
console.log('o.constructor.name=' + o.constructor.name);

Well, try it.

And be careful if you need to change the prototype of a function.

React

The props are passed as an argument to the constructor

If you need to access props in your component’s constructor, this.props won’t work. You have to specify them as a parameter. See the example.

(You know the difference between an argument and a parameter, right?)

Java

@Produces vs. @Consumes in Jersey

The @Produces annotation specify, what MIME types a method returns (produces). This method is later invoked only for HTTP requests with that MIME type in the Accept header.

The @Consumes annotation specify, what MIME types a method accepts. This method is later invoked only for HTTP requests with that MIME type in the Content-type header.

3. 3. 2016, kategorie:
comments powered by Disqus