Personnel how to emulate method overload in javascript
?
I know some programmers can, for example, I'm going to use gulp.
gulp has method .task
:
var gulp = require('gulp');
gulp.task('example-task', function(){
console.log('running example-task')
})
gulp.task('example-task-2', ['example-task'], function(){
console.log('running example-task')
})
But if I want to run some tasks
before others, I do this:
var gulp = require('gulp');
gulp.task('example-task', function(){
console.log('running example-task')
})
gulp.task('example-task-2', ['example-task'], function(){
console.log('running example-task')
})
When I want to run example-task-2
, I first run example-task
because example-task-2
is a kind of task
dependent on example-task
.
Anyway, this was just used to exemplify what I want to understand.
Perceive the signature of method .task
The first parameter is string
, and the second can be an array or an anonymous function.
How can I get this? As I come from JAVA, this would be easy: I would write two methods
with the same name and would only change the parameter received, it would look something like this:
public interface Gulp {
public void task(String taskName, AnonymousFunction run);
public void task(String taskName, List<Task> depencencies, AnonymousFunction run);
}
And in js, what would it be like?