title: Google App Script - How to use methods without defining their object
body: <p>I am writing the script behind a spreadsheet that has lots of durations on it in the format of (##:##.##) (ex 12:43.76). I need to write some code that converts this to just seconds. I wrote code that did the opposite, made seconds into that format. But when writing a custom formula for this, the .split method does not work. </p>
  
  <pre><code>function MTOS(input){
    String(input);
    if (typeof(input) != "string") {
      Logger.log("Not a string")}
    var array = input.split(":");
    Logger.log('The original string is: "' + input + '"');
  var min = Number(array[0]);
  var sec = Number(array[1]);
    Logger.log("min=" + min);
    Logger.log("sec=" + sec);
  var MIN = min*60;
    Logger.log(MIN);
  var ex = MIN+sec;
    Logger.log(ex);
  return ex;
  }
  </code></pre>
  
  <p>This is what I have in the script editor. The input is the parameter from the spreadsheet when I write the formula in the sheet itself (ex - =MTOS(3:23.53)). When I run the function in the script editor, it gives me the error "TypeError: Cannot call method "split" of undefined. (line 5, file "MTOS")" and in sheets, it returns "Error : Result was not a number." I understand that this is happening because input is not defined in the function itself, so .split cannot work. But how else can I write the custom formula for sheets? </p>
  
  <p>Thank you. </p>