Javascript function prototype and object prototype

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zhuchuji/article/details/81556727

Object.setPrototypeOf()

Object.setPrototypeOf(object, prototype) could change the prototype of the object directly, but only IE 10 and below do not support the method

Function.prototype

Every function has a prototype property, which could be set with assignment. We could achieve similar effect as Object.setPrototypeOf() with new.

function func() {
}
function createPrototype(prototype) {
    for (var key in prototype) {
        this[key] = prototype[key];
    }
}
func.prototype = new createPrototype({ key: value });

猜你喜欢

转载自blog.csdn.net/zhuchuji/article/details/81556727