函数声明如下:
# output: '12345'
和一个函数表达式如下:
function declaration() {}
如果必须选择,方法算作函数表达式吗?我的推理是因为它们没有像函数声明那样悬挂,并且在const expression = function() {};
关键字的右边省略了名称。
function
还是方法算作自己单独的类别?
答案 0 :(得分:1)
这是对象文字,您可以在其中使用表达式声明键和值。是的,这是一个函数表达式。要使其不是表达式,需要a)名称(function foo() {}
)和b)本身作为 statement 而不是较大表达式的一部分。
答案 1 :(得分:-1)
一切都归结为对象和原型。更多的是原型对象中的Function引用:
function Person() {}
Person.prototype.greet = function () {};
console.log(Person.prototype.greet);
Person.prototype.greet = new Function('');
console.log(Person.prototype.greet);
Person.prototype.greet = greet;
function greet() {}
console.log(Person.prototype.greet);
new Person().greet();//works either way
您可以引用函数表达式或函数声明。总而言之,它只是一个Function对象。
答案 2 :(得分:-1)
您可以取消这样的对象的方法:
const dbd = '01';
const dbm = '19';
const dby = '89';
const m = moment(`${dbd}${dbm}${dby}`, 'DD MM YY');