Joss Whedon isn't the sort of filmmaker you hire to just direct your movie. If you hire Whedon, you hire him 'cause you want him as a writer, too. Otherwise what's the point? Originally, though, Whedon was brought on to merely direct The Avengers based on a script written by screenwriter Zak Penn (perhaps best known for his work on the X-Men movies). When Whedon read Penn's draft of the script, though, he told Marvel Studios to pretend that the draft had never been written, claiming that Penn "had nothing." Pretty harsh, but hey - it's Hollywood! Whedon eventually produced a treatment and was later hired to rewrite the script from scratch. Had Whedon kept his mouth shut, chances are that audiences would have been treated to a very different Avengers indeed. Penn retained a story credit, though.
Sam Hill is an ardent cinephile and has been writing about film professionally since 2008. He harbours a particular fondness for western and sci-fi movies.