How to check if there is a function in Titanium Studio?

0

I need to check if a View exists on an OnClick event that runs the test function

if($.minhaview.propriedade == 'teste'){


   alert("existe um evento onClick com o valor teste");


}
    
asked by anonymous 03.02.2014 / 00:41

2 answers

0

If you added an element to onclick property, you can test it, for example:

if ($.minhaview.onclick) { 
  // faça algo...
}

But if you added the event with addEventListener('click', evento) ai the answer is: you can not check if there is an event in this element.

The observer that manages element events in javascript only allows you to add and remove events, but does not expose the list of events.

However, you can modify this behavior by modifying the event prototype, just as jQuery does.

You could create a way to store in some object property the list of events contained in it. But by default the W3C specification does not provide such exposure.

    
03.02.2014 / 03:41
0

If you just want to test whether the variable already has the value of an assigned function, you can use the typeof function.

if(typeof $.minhaview.propriedade === 'function')
{
  // ...
}
    
03.02.2014 / 01:12