Answer the question
In order to leave comments, you need to log in
JavaScript What is wrong with my module function (object)?
Tell me, please, what is wrong here?
How to write like this correctly? Please forgive me for such a stupid question, but I have not found a similar example anywhere (with a function argument in the form of an object).
var human = (function (person) {
person = {
firstName : "John",
lastName : "Doe",
age : person.age || 50,
eyeColor : person.eyeColor || "blue",
};
return person.age + ", " + person.eyeColor;
});
var getPerson = new human({ eyeColor: "Yellow" });
//
console.log(getPerson({ eyeColor: "Green" }));
Answer the question
In order to leave comments, you need to log in
var Human = (function (person) {
this.firstName = "John";
this.lastName = "Doe";
this.age = person.age || 50;
this.eyeColor = person.eyeColor || "blue";
this.toString = function() {
return person.age + ", " + person.eyeColor;
};
});
var pers = new Human({ eyeColor: "Yellow" });
//
console.log(pers);
var SampleClass = (function(localFirstDependencyName, localSecondDependencyName){
'use strict';
var _defaultSettings = {
option: 'option'
}
var constructor = function(settings){
this._settings = $.extend(this._settings || {}, _defaultSettings, settings);
this.publicField = null;
this._protectedField = null;
this._privateField = null;
};
$.extend(constructor.prototype, {
publicConstant: 'Constant',
protectedConstant: 'Constant',
_privateConstant: 'Constant',
//#region Public
publicMethod: function () {
this._protectedMethod();
},
//#endregion
//#region Protected
_protectedMethod: function () {
},
//#endregion
//#region Private
_privateMethod: function(self, value){
},
//#endregion
});
return constructor;
}(globalFirstDependencyName, globalSecondDependencyName));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question