| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- const builtins = {
- concat: function () {
- let str = ""
- for (let i = 0; i < arguments.length; i++) {
- str += arguments[i].value
- }
- return {
- value: str
- }
- },
- length: function (str) {
- return {
- value: str.value.length
- }
- },
- charAtIndex: function (str, i) {
- return {
- value: str.value.charAt(i.value)
- }
- }
- }
- const my_handler = {
- get: function (target, prop) {
- let methods = Object.keys(builtins)
- if (methods.includes(prop)) {
- return builtins[prop]
- } else {
- console.error("Undefined function call! No such function: ", prop)
- }
- },
- }
- const proxy_obj = new Proxy({}, my_handler)
- let _
- module.exports = function (self) {
- _ = self
- return proxy_obj
- }
|