5
Good staff would like to know if it is possible to access a method of a class(javascript) without knowing if the variable by instance it.
function SDK(dynamicUrl) {
var data = 'DATA';
var atual = null;
var counter = 0;
this.onComplete = function (){ }
this.onError = function () { }
this.start = function ( ) {
alert('HUE BR')
}
}
//Tendando acessar o metodo
SDK.start();
*I know I could access it by creating a variable and instantiating the class in question, but by a limitation of the project in question this is not possible T.T
var sdk = new SDK('HUE BR');
sdk.start();
URL of the script: http://jsfiddle.net/8twxajLh/
Why don’t you use it directly
SDK.start = function() {...}
. In this case it is creating a function within a function (which is an object).– Wakim
So this way I can not because I do not have access to the data of the instance in question but even so thank you.
– Douglas dos Santos
Directly from
SDK
can’t. Why can’t you usenew
?– bfavaretto
So face is a limitation of the project( I am responsible for the script ), because in my case I am not responsible for creating the new SDK(), ie I have no access to variable only have access to class T.T; But Valew msm so if there is no way msm I will try something else
– Douglas dos Santos
If you have a reference to the class, even if it is not the class itself, you can still create an instance of it - see http://jsfiddle.net/d3a5ozvofor example/
– carlosfigueira