- 主题:javascript 中,函数的原型对象 是啥?
your book is too old, arrow functions do not have a "prototype" property.
F.prototype is the prototype of the newly-created object passed to F
as "this" context when evaluating "new F" or "new F(...)".
【 在 zhanghaoX (环顾四方有效) 的大作中提到: 】
: 每一个函数都包含一个prototype属性,这个属性是指向一个对象的引用,这个对象称
: 做“原型对象” (prototype object )。每一个函数都包含不同的原型对象。
: 那么到底是啥?
: ...................
--
FROM 183.195.251.*
【 在 zzjyingzi (十六点五) 的大作中提到: 】
: 理解javascript是基于对象的,这个就不难理解。
: 因为基于对象,所以才有原型链,变量、方法是挂接在对象上的,在方法中的直接体现就是this的指向,函数默认this指向的对象在浏览器中是window,window默认挂接全局变量和方法,而prototype就是指向对象的API,这样可以将函数的指向对象更换为其他对象,比如可以
: var a = 1;
: function asd(){
: alert(this.a);
: }
: asd();//这时候this指向window
only applies to top-level function calls.
function calls in another function without a base ref
has `this' set to undefined.
: asd.prototype.s = function(){
: this.a = 2;
: alert(this.a);
: };
: var z = new asd(); //构造之后this就指向新的作用域,这时候函数的this为undefined
: z.s(); //这时候是2
--
FROM 202.120.55.*
【 在 zhanghaoX (环顾四方有效) 的大作中提到: 】
: 你指的是用 new Function( ) 来定义函数的情况吗?
no.
: 如果是 函数定义表达式 或 函数声明 来定义函数 ,那么函数的原型对象是啥?
http://www.ecma-international.org/ecma-262/6.0/index.html#sec-function-definitions-runtime-semantics-evaluation
the prototype property is set on Perform MakeConstructor(closure).
--
FROM 202.120.55.*