Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript error { [native code] }

Tags:

javascript

Hi I'm trying to do some basic javascript and am getting "native code" instead of what I want:

<script type="text/javascript">
var today = new Date();
document.write(today  + "<br />");
//document.write(today.length  + "<br />"); - was getting "undefined"
//document.write(today[0]  + "<br />"); - was getting "undefined"

document.write(today.getMonth  + "<br />");
document.write(today.getMonth  + "<br />");
document.write(today.getFullYear  + "<br />");

</script> 

output was:

Fri Jan 13 14:13:01 EST 2012
function getMonth() { [native code] } 
function getDay() { [native code] } 
function getFullYear() { [native code] } 

what I want is to get the current Month, Day, Year and put it into an array variable that I will be able to call later on. I'm not getting far because of this native code. Can someone tell me what it is and hopefully, more importantly I can complete this project? Thank you for your time and help, it is much appreciated!

like image 551
ristenk1 Avatar asked Jan 13 '12 19:01

ristenk1


2 Answers

The getMonth and the rest are functions, not properties, when you call just today.getMonth you are getting a reference to the actual function. But, if you execute it using parenthesis, you get the actual result.

Your code should be:

document.write(today.getMonth()  + "<br />");
document.write(today.getMonth()  + "<br />");
document.write(today.getFullYear()  + "<br />");
like image 172
cambraca Avatar answered Oct 09 '22 20:10

cambraca


You are missing the parenthesis().

document.write(today.getMonth()  + "<br />");
document.write(today.getMonth()  + "<br />");
document.write(today.getFullYear()  + "<br />");
like image 26
ShankarSangoli Avatar answered Oct 09 '22 19:10

ShankarSangoli