Skip to content

Instantly share code, notes, and snippets.

@KaMeHb-UA
Created May 2, 2018 13:26
Show Gist options
  • Save KaMeHb-UA/c1cd45438f8b0d5a2427e4b743feade2 to your computer and use it in GitHub Desktop.
Save KaMeHb-UA/c1cd45438f8b0d5a2427e4b743feade2 to your computer and use it in GitHub Desktop.
Simple browser __filename and __dirname realization (checked on Chrome and Firefox)
(()=>{const __filename=(a=>{return `${a[a.length-3]}://${a[a.length-2]}`})((new Error('')).stack.split(/(\w+):\/\/(\S+):\d+:\d+/)),__dirname=(a=>{a.pop();return a.join('/')})(__filename.split('/'));(()=>{
console.log([__filename, __dirname])
})()})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment