JavaScript:UncaughtTypeError:对象不是函数

JavaScript:UncaughtTypeError:对象不是函数,javascript,Javascript,我的代码中有一个错误 function checkWrong() { var programInfo = {}; var bookedQueue = new programInfo(); bookedQueue.title = "cost"; bookedQueue.startTime = "13:50"; console.log(bookedQueue.title); } JavaScript:UncaughtTypeError:对象不是函数 上述错误发生在第6行。我

我的代码中有一个错误

function checkWrong()
{
  var programInfo = {};
  var bookedQueue = new programInfo();

  bookedQueue.title = "cost";
  bookedQueue.startTime = "13:50";

  console.log(bookedQueue.title);
}
JavaScript:UncaughtTypeError:对象不是函数


上述错误发生在第6行。我应该怎么做才能解决这个问题?

不确定,但我很确定您想要这个:

function checkWrong() {
    var programInfo = function () {};
    var bookedQueue = new programInfo();

    bookedQueue.title = "cost";
    bookedQueue.startTime = "13:50";

    console.log(bookedQueue.title);
}

不能对对象使用
new
,只能对函数使用。有关详细信息,请参阅

因此,你可以:

var programInfo = {};
programInfo.title = "cost";
或:


programInfo不是一个函数,是吗?是的,我希望programInfo只使用一个对象。我使用的是Chrome浏览器。注意:@jgillich的答案比我的更完整。
var programInfo = function () {
    // If you want, you can set default properties here, like:
    // this.title = 'default title';
};

var bookedQueue = new programInfo();

bookedQueue.title = "cost";