How can i run Ionic 2 code inside javascript function

hey guys, i want to send sms to user but i can’t run ionic code inside js function .
but my apps is a Ionic 2 typescript
how can i run Ionic 2 code inside javascript function??? my function is look like this :

              this.loading=Loading.create({
              content:'Prise du rendez-vous en cours...',
              showBackdrop:false
          });
          this.nav.present(this.loading);
          /* FUNCTION FOR CATSHING SUCCENDING SEND MESSAGE */
          var success=function(){
            this.loading.dismiss();
            this.nav.present(Alert.create({
                title: "Message envoyé",
                subTitle: "Un sms vous sera envoyé en cas de prise de votre rendez-vous. Merci!!!",
                buttons: ["Ok"]
            }));
          }
          /* FUNCTION FOR CATSHING ERROR ON SENDING SMS */
          var error=function(){
            this.loading.dismiss();
             this.nav.present(Alert.create({
                title: "Erreur",
                subTitle: "Message non envoyé",
                buttons: ["Ok"]
            }));
          }
           /* OPTIONS FOR FOR PARAMETERS ON MESSAGE */
            var options = {
                replaceLineBreaks: true, // true to replace \n by a new line, false by default
                android: {
                    intent:''
                    // intent: 'INTENT'  // send SMS with the native android SMS messaging
                    //intent: '' // send SMS without open any other app
                  }
              };
              /* HERE THE SENDING SMS FUNCTION */
              sms.send(this.number,"Nom : " + this.myName + "\n" + "Date : " + this.myDate + "\n" + "Heure : " + this.myHour,options,success,error);
public error(): void {
     this.loading.dismiss();
     this.nav.present(Alert.create({
        title: "Erreur",
        subTitle: "Message non envoyé",
        buttons: ["Ok"]
    }));
}

@xr0master, okey thanks for the reply