CNode

大家好!谁能解释下http.request 为什么不支持含原型链的对象?

问答
Vvince78发布于10 年前最后回复10 年前2 回复3801 浏览0 收藏

举个例子:

var options={protocal:'https:',__proto__: require('url').parse(url)}
var req=new http.ClientRequest(options,cb)
//error :connect ECONNREFUSED 127.0.0.1:80
查看回复

回复 (2)

V
vince78#1·10 年前

内部用了 util._extend end!

F
FoghostCn#2·10 年前

楼上说的对,util._extend方法内部实现用了Object.keys方法,看看他的文档:

The Object.keys() method returns an array of a given object's own enumerable properties, in the same order as that provided by a for...in loop (the difference being that a for-in loop enumerates properties in the prototype chain as well).

这个方法并不会返回对象原型链上的属性,over!

参与回复
登录后即可参与回复。登录