modify the extend method (copied from jQuery)