I have a legal JS question that is hard to explain. Please forgive my obscure manner of speaking and try to understand this idea .: P
JS objects may have properties. You can assign functions to properties. You can override the properties of an object without changing its other properties.
var myObject = {};
myObject.myFunction = function() { return 1; };
myObject.bar = "Bar";
myObject.myFunction = function() { return "Another function here"; }
console.log( myObject.bar );
But objects themselves can be functions.
Question 1 : What is the correct term for a function of such an object-function? I will call it "main function-function-object" below.
I understand that in JS, all funcitons are functional objects, so it’s incorrect to say "object-object function". But when the object "foo" can perform two functions: foo()and foo.bar(), there must be an unambiguous way to distinguish two in speech.
Because object objects are objects, they can have properties.
Question 2 : How to redefine the main function of a functional object, leaving other properties of the function object unchanged?
An example of what I want:
myFunctionObject = function () { return 1; }
myFunctionObject.bar = "Bar";
myFunctionObject = function () { return "Another function here"; }
console.log( myFunctionObject.bar );
The main function of the function-object must be stored somewhere ... Some hidden property, possibly e. g myFunctionObject.__function__ = function () { return 1; }?
PS - JS. , JS-kungfu [CodeWars] (http://codewars.com.