Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

the object doesn't accept property or method

I have this function in my scripts and Internet Explorer throws an error: "el objeto no acepta la propiedad o el metodo trunc" which means something like "the object doesn't accept property or method trunc"

function minutesToString(a){
  var hours = Math.trunc(a/60);
  var minutes = a % 60;
  return(hours +" hr "+ minutes + " m");
}

On chrome, firefox, etc. works perfectly.

like image 812
Sebastian Breit Avatar asked Dec 18 '25 06:12

Sebastian Breit


1 Answers

Add a polyfill for Math.trunc(). Include the following code somewhere before using Math.trunc()

Math.trunc = Math.trunc || function(x) {
  if (isNaN(x)) {
    return NaN;
  }
  if (x > 0) {
    return Math.floor(x);
  }
  return Math.ceil(x);
};
like image 53
NTL Avatar answered Dec 20 '25 19:12

NTL