功能和对象。 [英] Functions and Objects.

查看:58
本文介绍了功能和对象。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看看这段代码。

展开 | 选择 | Wrap | 行号

解决方案

第一个创建你的副本构造函数...第二个创建对象测试的新实例...用你可以做的第一个:

展开 | 选择 | Wrap | 行号



第一个创建构造函数的副本...第二个创建一个对象测试的新实例...用你可以做的第一个实例:

展开 | 选择 | 换行 | 行号

< br>


第一个创建c的副本onstructor ...



从技术上讲,它没有被复制,你创建了一个指向函数对象的链接。


OP:


当新时使用关键字,构造函数的原型绑定到返回的对象的原型


记住该函数是对象。


考虑在创建构造函数并稍后添加原型方法时会发生什么:

展开 | 选择 | Wrap | 行号

Have a look at this code.

Expand|Select|Wrap|Line Numbers

解决方案

the first creates a copy of your constructor ... the second creates a new instance of the object test ... with the first you you could even do:

Expand|Select|Wrap|Line Numbers


the first creates a copy of your constructor ... the second creates a new instance of the object test ... with the first you you could even do:

Expand|Select|Wrap|Line Numbers


the first creates a copy of your constructor...

technically, it is not copied, you create a link to the function object.

OP:

when the "new" keyword is used, the constructor''s prototype is bound to the returned object''s prototype.

remember that function are objects.

consider what happens when you create a constructor function and add prototype methods later :


Expand|Select|Wrap|Line Numbers


这篇关于功能和对象。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆