How is it possible in js to check whether a function of a particular object?

Is object modal, there is a function openModal(), the question is this - how inside the function openModal check when you call - whether it belongs to this object or not?
August 19th 19 at 23:36
2 answers
August 19th 19 at 23:38
javascript.ru/this

if (this == modal)
alert("Call from modal");


Generally there is a good chance that you have an error in architecture, time this is need.
In scope openModal may not be the object modal. - jaiden_Thiel commented on August 19th 19 at 23:41
Well I write as to traverse the dependency in visibility in my superfluous - the question is not about that. For this there are all sorts of DI-approaches, described a hundred times. - Gerry.Koss commented on August 19th 19 at 23:44
: There is no error, explain why. There is a modal object, such objects can be several - modal2, modal3, etc. and is a function openModal. At the moment it works through the transmission parameter is passed the id of the unit and it's unit opens in moduli. But there is a problem, because if I interact with a modal or other object I want to call it openModal method without passing a parameter and respectively on the inside I have to check if I call this method from the object, he takes the id from the object, if the method is invoked not through the object ( modal.openModal() ), and directly - i.e. just openModal it should handle the parameter. That's what the challenge is. - reba commented on August 19th 19 at 23:47
Duck do the check inside the method on a parameter. And throw an exception allevaite it svehu code. - gaylord.Satterfie commented on August 19th 19 at 23:50
I'm certainly not strong in javascripteval the PLO, but in my modal.openModal() and openModal is calls two different functions, one of which is the class method. Accordingly, they have different implementation. Likely in the method openModal (which is class method not a function!) to call a function openModal and bring back the current ID. - Gerry.Koss commented on August 19th 19 at 23:53
August 19th 19 at 23:40
To explain you do not know. If I guessed correctly.
in strict mode, this function is called without the context will be undefined
here is this.constructor will throw acceptn - jaiden_Thiel commented on August 19th 19 at 23:43

Find more questions by tags JavaScriptOOP