Just in case, I would like to draw your attention to the fact that creating methods in the constructor is inefficient in terms of memory. In fact, in the first example, a new function test is created from the @Grundy response when creating each new MyObject object. In most cases, this is an undesirable effect (the use of the constructor, as a closure, I do not specifically consider here).
In addition, by creating methods in the constructor, you complicate the inheritance mechanism.
As a result, in most cases it is more correct to bind methods to the prototype of the object being created, namely:
var MyObject = function(foo) { // Инициализация свойств, уникальных для каждого ЭКЗЕМПЛЯРА MyObject. this.foo = foo; }; MyObject.prototype.test = function() { console.log(this.foo); }; var my = new MyObject('test'); my.test(); // Выведет "test"