{"action":"opened","issue":{"url":"https://api.github.com/repos/bloomberg/ocamlscript/issues/112","repository_url":"https://api.github.com/repos/bloomberg/ocamlscript","labels_url":"https://api.github.com/repos/bloomberg/ocamlscript/issues/112/labels{/name}","comments_url":"https://api.github.com/repos/bloomberg/ocamlscript/issues/112/comments","events_url":"https://api.github.com/repos/bloomberg/ocamlscript/issues/112/events","html_url":"https://github.com/bloomberg/ocamlscript/issues/112","id":135295312,"number":112,"title":"investigate inline `js` code directly","user":{"login":"bobzhang","id":747051,"avatar_url":"https://avatars.githubusercontent.com/u/747051?v=3","gravatar_id":"","url":"https://api.github.com/users/bobzhang","html_url":"https://github.com/bobzhang","followers_url":"https://api.github.com/users/bobzhang/followers","following_url":"https://api.github.com/users/bobzhang/following{/other_user}","gists_url":"https://api.github.com/users/bobzhang/gists{/gist_id}","starred_url":"https://api.github.com/users/bobzhang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bobzhang/subscriptions","organizations_url":"https://api.github.com/users/bobzhang/orgs","repos_url":"https://api.github.com/users/bobzhang/repos","events_url":"https://api.github.com/users/bobzhang/events{/privacy}","received_events_url":"https://api.github.com/users/bobzhang/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-02-22T02:27:26Z","updated_at":"2016-02-22T02:27:26Z","closed_at":null,"body":"Note that this is unsafe behavior, but just like `Obj` module in ocaml, it's very helpful in some scenarios:\r\n\r\nIn most cases we can write js code in another js file and use `external` to refer it in ocaml, there are two disadvantages here:\r\n1. we have to create a new js file\r\n2. it will introduce another build step, even worse, if we want to support different module systems in js, we have to introduce yet another transpiler.\r\n\r\nproposal to insert js code \r\n\r\n```ocaml\r\nexternal imul : int -> int -> int = \"\"\r\n[@@js.code {\r\nif (Math.imul){ Math.imul\r\n} else {\r\n  function polyfill (){\r\n ....\r\n}\r\n}\r\n|}]\r\n```\r\n\r\nNote that implementation is not very straightforward, we need insert  the js code in the definition instead of call site\r\n\r\n\r\nAnother way to insert js code (I am not sure it is worth doing this, just for disucssion)\r\n\r\n``` ocaml\r\nlet f  x y = \r\n   {js| console.log(x,y) ; debugger ; |js}\r\n  x + y\r\n```"}}