Coding Challenge Practice – Question 57

The task is to implement Object.create()

The boilerplate code

function myObjectCreate(proto) {
// your code here
}

If the prototype is null or not an object, throw an error

if(proto === null || typeof !== “object”) {
throw new TypeError…


This content originally appeared on DEV Community and was authored by Bukunmi Odugbesan

The task is to implement Object.create()

The boilerplate code

function myObjectCreate(proto) {
  // your code here
}

If the prototype is null or not an object, throw an error

if(proto === null || typeof !== "object") {
 throw new TypeError("Prototype must be an object or null")
}

An empty constructor function is declared, because every object in Javascript is created using a constructor.

function F() {}

The prototype of the empty constructor is set to the one provided

F.prototype = proto

Then, a new instance is returned

return new F()

The final code

function myObjectCreate(proto) {
  // your code here
  if(proto === null || typeof proto !== "object") {
    throw new TypeError("Prototype must be object or null")
  }

  function F() {}
  F.prototype = proto;
  return new F;
}

That's all folks!


This content originally appeared on DEV Community and was authored by Bukunmi Odugbesan


Print Share Comment Cite Upload Translate Updates
APA

Bukunmi Odugbesan | Sciencx (2025-11-16T21:38:33+00:00) Coding Challenge Practice – Question 57. Retrieved from https://www.scien.cx/2025/11/16/coding-challenge-practice-question-57/

MLA
" » Coding Challenge Practice – Question 57." Bukunmi Odugbesan | Sciencx - Sunday November 16, 2025, https://www.scien.cx/2025/11/16/coding-challenge-practice-question-57/
HARVARD
Bukunmi Odugbesan | Sciencx Sunday November 16, 2025 » Coding Challenge Practice – Question 57., viewed ,<https://www.scien.cx/2025/11/16/coding-challenge-practice-question-57/>
VANCOUVER
Bukunmi Odugbesan | Sciencx - » Coding Challenge Practice – Question 57. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/11/16/coding-challenge-practice-question-57/
CHICAGO
" » Coding Challenge Practice – Question 57." Bukunmi Odugbesan | Sciencx - Accessed . https://www.scien.cx/2025/11/16/coding-challenge-practice-question-57/
IEEE
" » Coding Challenge Practice – Question 57." Bukunmi Odugbesan | Sciencx [Online]. Available: https://www.scien.cx/2025/11/16/coding-challenge-practice-question-57/. [Accessed: ]
rf:citation
» Coding Challenge Practice – Question 57 | Bukunmi Odugbesan | Sciencx | https://www.scien.cx/2025/11/16/coding-challenge-practice-question-57/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.