@todojs/

Proxy 10 - pathBuilder()

JavaScript

No description

fork
loading
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function pathBuilder(root) {
    var parts = [];
    var folder = new Proxy(
        function () {
            var returnValue = '/' + root + '/' + parts.join('/');
            parts = [];
            return returnValue;
        },
        {
            get: function (object, prop) {
                parts.push(prop);
                return folder;
            }
        }
    );
    return folder;
}

var pathExample = pathBuilder('base');
console.log(pathExample.esto.solo.es.una.prueba());     // /base/esto/solo/es/una/prueba
Native Browser JavaScript