I believe you are mistaken in your understanding of asm.js.
First off, from their FAQ
Q. Is asm.js a new language?
And you asked clarification added :
But how is it possible to write one [an asm.js application] in C++
You don't write an "asm.js application", rather asm.js is a target1 to compile your C++ code to.
This article by John Resig provides a number of details that may better explain how asm.js would be used.
Starting with this image:
You also asked:
And if I write the code in C++, then how to use the js API-s
And going back to Resig's article, there are two key quotes for your question:
For some additional research, emscripten has a tutorial that might help you get started with understanding how to take C++ code, run it through LLVM, and then target asm.js.