你怎么做到这一点?像PHP有call_user_func
我正在尝试将回调函数传递给jQuery.animate(),就像这样
...
complete: function(){
// do_something
call_function(my_callback); // here need to call my_callback
}
...
Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个sayHello接受一个参数的函数name.它应该返回一个连接的字符串,即"Hello,name".
这是我的代码
function sayHello(name) {
return "Hello " + name;
}
return sayHello;
Run Code Online (Sandbox Code Playgroud)
当我跑步时return sayHello,我看到以下内容:
SyntaxError: Illegal return statement
Run Code Online (Sandbox Code Playgroud)
当我跑sayHello:
function sayHello(name) {
return "Hello " + name;
}
sayHello;
Run Code Online (Sandbox Code Playgroud)
我看到了这个:
=> [Function: sayHello]
Run Code Online (Sandbox Code Playgroud)
所有尝试都会导致这种或那种错误.我已经在MDN上研究了函数语法,我相当确定我已经检查了语法.你能指出我错过的东西吗?
提前感谢您的所有帮助.
- 更新:感谢Richard Kho,Arun P Johny,hemnath mouli和Shawn的回复以及.我非常感谢你的帮助.
这个问题与调用函数不同的原因是术语"调用函数"是我不知道应该执行的关键步骤,以及我没想过要使用的关键词汇术语.
再次感谢!.
我正在观看几年前关于学习 javascript 的 YouTube 视频,在视频中,除了在我的 VScode 上之外,代码似乎都可以工作。
这是代码,请让我知道我可能错过了什么:
function Person(firstName, lastName, dob) {
this.firstName = firstName;
this.lastName = lastName;
this.dob = new Date(dob);
this.dateBio = function() {
return `${this.dob.getFullYear}`
}
}
Person.prototype.fullName = function() {
return `${this.firstName} ${this.lastName}`
}
const person1 = new Person('James','Smith', '27 July 1967');
const person2 = new Person('Mary', 'Franklin', '5 November 1991')
console.log(person1.fullName)Run Code Online (Sandbox Code Playgroud)