I'm relatively new to javascript, just digging through faker package I downloaded from npmjs.
The following is one of the method that I can call to generate a random color by calling the method like this: faker.commerce.color(). I get how the method works but I don't understand why it works.
This bit : var Commerce = function(faker) I find especially confusing, why don't you just make commerce an object, make a constructor with it and then call the function inside the object?. I've written the bit I find confusing in the code section below:
var Commerce = function (faker) {
var self = this; <------ *what is "this"? usually it should refer to the argument "faker" but looking down below seeing as you can call "commerce.color", self must equal to Commerce?*
self.color = function() {
return faker.random.arrayElement(faker.definitions.commerce.color);
}; *<--- what is "self" referencing to here then?*
if Commerce = function(faker), by calling faker.commerce.color(), aren't you doing: faker.function(faker).color()?