Is there any reason to use Object.create() or new in JavaScript?

前端 未结 4 540
[愿得一人]
[愿得一人] 2021-01-12 01:23

I\'ve been using the new keyword in JavaScript so far. I have been reading about Object.create and I wonder if I should use it instead. What I don\

4条回答
  •  余生分开走
    2021-01-12 02:25

    The exact source code for the Object.create() function is:

    function Object.Create(proto, propertiesObject)
    {
        var obj = {};
    
        Object.setPrototypeOf(obj, proto);
    
        if(propertiesObject)
        {
            Object.defineProperties(obj, propertiesObject);
        }
    
        return obj;
    }
    

提交回复
热议问题