{ "data": { "question": { "questionId": "2770", "questionFrontendId": "2754", "boundTopicId": null, "title": "Bind Function to Context", "titleSlug": "bind-function-to-context", "content": null, "translatedTitle": null, "translatedContent": null, "isPaidOnly": true, "difficulty": "Medium", "likes": 14, "dislikes": 0, "isLiked": null, "similarQuestions": "[]", "exampleTestcases": "function f(multiplier) { return this.x * multiplier; }\n{\"x\":10}\n[5]\nfunction speak() { return \"My name is \" + this.name; }\n{\"name\":\"Kathy\"}\n[]", "categoryTitle": "JavaScript", "contributors": [], "topicTags": [], "companyTagStats": null, "codeSnippets": null, "stats": "{\"totalAccepted\": \"340\", \"totalSubmission\": \"388\", \"totalAcceptedRaw\": 340, \"totalSubmissionRaw\": 388, \"acRate\": \"87.6%\"}", "hints": [ "The easiest way to solve this is to use the built-in fn.apply() method.", "Without built-in methods, you need to figure out a way to call the function (this) from context object. That will associate \"this\" appropriately.", "You can create a new Symbol(). Attach the symbol to the context object and set the method to be \"this\". Then call the method on the symbol." ], "solution": null, "status": null, "sampleTestCase": "function f(multiplier) { return this.x * multiplier; }\n{\"x\":10}\n[5]", "metaData": "{\n \"name\": \"jsonParse\",\n \"params\": [\n {\n \"name\": \"fn\",\n \"type\": \"string\"\n },\n {\n \"type\": \"string\",\n \"name\": \"obj\"\n },\n {\n \"type\": \"string\",\n \"name\": \"inputs\"\n }\n ],\n \"return\": {\n \"type\": \"integer\"\n },\n \"languages\": [\n \"javascript\",\n \"typescript\"\n ],\n \"manual\": true\n}", "judgerAvailable": true, "judgeType": "large", "mysqlSchemas": [], "enableRunCode": true, "enableTestMode": false, "enableDebugger": false, "envInfo": "{\"javascript\": [\"JavaScript\", \"

Node.js 16.13.2.

\\r\\n\\r\\n

Your code is run with --harmony flag, enabling new ES6 features.

\\r\\n\\r\\n

lodash.js library is included by default.

\\r\\n\\r\\n

For Priority Queue / Queue data structures, you may use 5.3.0 version of datastructures-js/priority-queue and 4.2.1 version of datastructures-js/queue.

\"], \"typescript\": [\"Typescript\", \"

TypeScript 5.1.6, Node.js 16.13.2.

\\r\\n\\r\\n

Your code is run with --harmony flag, enabling new ES2022 features.

\\r\\n\\r\\n

lodash.js library is included by default.

\"]}", "libraryUrl": null, "adminUrl": null, "challengeQuestion": null, "__typename": "QuestionNode" } } }