Fields
They are also known as class instance fields, class variables or member variables.
A field is a Variable of any type that is declared directly inside a class or structure.
Fields should not be accessed directly but always through Properties.
Accessing - Using Public
function class_Example(name, address) {
// public fields
this.name = name;
this.address = address;
}
var myObject = new class_Example("one","two");
var string1 = myObject.name
Accessing - Using Methods
This uses private fields
function class_Example(name, address) {
// private fields
var privateString = "some text";
// assuming that this variable is used inside one of the class methods.
}
var myObject = new class_Example("one","two");
var string1 = myObject.name
Accessing - Using Properties
var myObject = {
Property1 : 10,
get Property1_Get() {
return this.Property1;
}
}
var myObject = {
Property1 : 10,
set Property1_Set(val) {
this.Property1 = val;
}
}
© 2022 Better Solutions Limited. All Rights Reserved. © 2022 Better Solutions Limited TopPrevNext