JavaScript:字段或属性 [英] JavaScript: fields or properties

查看:101
本文介绍了JavaScript:字段或属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我看过的所有JavaScript教程中,都提到了有关对象属性的内容.但是为什么他们称其为财产?例如构造函数属性var a = function{this.b},其中b再次称为属性.据我所知,属性具有getter和/或setter,所以应该将它们称为字段,不是吗?

In every JavaScript tutorial that I have looked there is something mentioned about a property of an object. But why do they call it a property? e.g. constructor property, var a = function{this.b} where b is again called property. As far as I know properties have getter and/or setter, so those one should be called field, shouldn't they?

推荐答案

某些浏览器供应商已实现JavaScript属性的getter/setter方法.

Some browser vendor have implemented getters/setters for JavaScript properties.

FF和Webkit为DOM对象实现了__defineGetter____defineSetter__,并为ECMA规范之外的Object获取和设置了__defineGetter____defineSetter__.但是,IE 8+和IE 8+均具有Object.defineProperty(来自ECMA规范).在此处

FF and Webkit has __defineGetter__and __defineSetter__ implemented for DOM objects and get and set for Object's which is outside of the ECMA specification. However both and also IE 8+ has the Object.defineProperty (from the ECMA specification). Read about it here

关于您的原始问题,我想说它在JavaScript中称为属性的原因是它是一种动态语言,基本标记仅使用属性和局部var.由于所有内容都绑定到特定的范围层次结构,因此您在每个级别上拥有的树分支都是不同的.道格拉斯·克罗克福德(Douglas Croockford)将它们命名为属性:)

As for you original question, I would say that the reason it's called property in JavaScript is that it's a dynamic language and the basic markup uses only properties and local var's. Since everything is bound to a specific scope-hierarchy all you have is different tree-branches on each level. And Douglas Croockford named them properties :)

这篇关于JavaScript:字段或属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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