Javascript Getter和Setters [英] Javascript Getters And Setters

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

问题描述

有人可以告诉我有关javascript中的getter和setter的信息吗?什么是吸气剂和吸气剂?我们在哪里可以使用它们?使用它们有什么好处?

Can somebody please tell me about getters and setters in javascript? What are actually getters and setters? Where we can use them? What are the benefits of using them?

推荐答案

Gettersetter都是函数.

Getter将在从具有Getter的变量/对象中检索值时调用.Getter函数必须返回值.

Getter will call when a value is retrieve from variable/object(which has Getter) Getter function must return value.

var i=count;

如果已经定义了计数的吸气剂,它将调用.

if the count's getter is already defined, it will call.

Setter将在将值分配给具有Setter的变量/对象时调用

Setter will call when a value is assign to a variable/object(which has Setter)

count=10

如果已经定义了计数的setter,它将调用.

if the count's setter is already defined, it will call.

看一下这个例子,以便您可以轻松理解Gettersetter

take a look at this example so that you can easily understand the use of Getter and setter

当某个对象的属性之一更改时,如何在该对象内得到通知?

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

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