0

I need to shorten my functions (I use them a lot, if i shorten them probably my app needs less storage)

For Example I have navigator.notification.confirm

it is a function. I call it like this : navigator.notification.confirm(a, b, c, [d, e, f, ...])

I want to shorten it as : confirm(a, b, c, [d, e, f, ...])

I used var confirm = navigator.notification.confirm but it doesn't work :(

I can use function confirm(a, b, c, d) { navigator.notification.confirm(a, b, c, d) }

but isn't there any shorter way ?

1 Answers1

1

Here is an example of how I do this for navigator.notification.alert:

I put this in my function that is called from the deviceReady event.

    //Shortcut for navigator.notification.alert
    if (navigator.notification) {
        window.alert = function (message,func,title,buttonTxt) {
            if(!func){
                func = null;
            }
            navigator.notification.alert(message, func, title, buttonTxt);
        };
    }

Now with this code in place, anytime I want to alert something I can do this:

alert('hi');

instead of:

navigator.notification.alert('hi');
Dawson Loudon
  • 6,029
  • 2
  • 27
  • 31
  • 1
    That is short sighted. You write this function once, then anytime you want to call it you use `alert(message);`. That is shorter in the long run. – Dawson Loudon Mar 14 '14 at 16:26