How does JS implement the file path of the called function?
PHP中文网
PHP中文网 2017-05-19 10:15:49
0
2
476

Like the title, how to achieve it if possible? The following is the code. The requirement is that it can only be implemented in function foo.

// "/lib/a.js"

export default function foo () {
    // code here
    return path
}

// "/src/pages/b.js"

import foo from "../../lib/a.js"
let str = foo()
console.log(str) // 成功打印本地文件路径

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(2)
Peter_Zhu
export default function foo () {
    // code here
    return __dirname
}
淡淡烟草味
    // "/lib/a.js"
    
    export default function foo () {
        // code here
        return path
    }
    
    // "/src/pages/b.js"
    
    var str = "../../lib/a.js"
    
    import foo from str
    foo()
    console.log(str) // 成功打印本地文件路径

Please ignore any grammatical errors

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template