Support callbacks in newResource

According discuss #543