[英]why does a show "function getFullYear() { [native code for Date.getFullYear, arity=0] }" rather than the value returned by the method?
In the Google Apps Script Editor I have the following code在 Google Apps 脚本编辑器中,我有以下代码
function t(){
var d = new Date;
Logger.log(d);
var y = d.getFullYear;
Logger.log(y);
if (y == 2013) {
Logger.log("yes");
} else {
Logger.log("No");
}
}
This stores a reference to the getFullYear
function in y
: 这将在
y
存储对getFullYear
函数的引用:
var y = d.getFullYear;
This calls the getFullYear
function and stores the result of the function call in y
: 这将调用
getFullYear
函数并将函数调用的结果存储在y
:
var y = d.getFullYear();
// ------------------^^
Perhaps you're confused because you can create objects with or without the parentheses (assuming you don't need to pass any arguments of course): 也许你很困惑,因为你可以创建带或不带括号的对象(假设你当然不需要传递任何参数):
var d1 = new Date;
var d2 = new Date();
Both of those do the same thing but that's just a quirk/feature of the new
operator. 这两个都做同样的事情,但这只是
new
运营商的一个怪癖/特征。
var y = d.getFullYear; var y = d.getFullYear; chanege var y = d.getFullYear();
更改 var y = d.getFullYear(); your problems must solve with this way.
你的问题必须用这种方式解决。 you forgot that "()"
你忘了那个“()”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.