Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Missing '()' invoking a constructor

I have this code below to return the current year (I also have it in jsFiddle). jsFiddle keeps giving me an error: "Missing '()' invokes a constructor", and I don't know what it means or how to get rid of it. The code still works, but I'd like to know what the heck is causing the error:

HTML:

jQuery:

var currentYear = (new Date).getFullYear();
$(document).ready(function() {
    $("#year").text(currentYear);
});

Thanks!

like image 858
alexwc_ Avatar asked Sep 30 '13 15:09

alexwc_


2 Answers

It is the new Date part that is causing the warning. This will fix it:

var currentYear = (new Date()).getFullYear();
like image 143
musefan Avatar answered Nov 18 '22 15:11

musefan


You are missing the brackets for Date, it should be Date()

So:

var currentYear = (new Date()).getFullYear();
like image 41
Paddyd Avatar answered Nov 18 '22 14:11

Paddyd