1. The best getters / setters are smart.
Here is a javascript example from mozilla:
var o = { a:0 } // `o` is now a basic object Object.defineProperty(o, "b", { get: function () { return this.a + 1; } }); console.log(ob) // Runs the getter, which yields a + 1 (which is 1)
I used these LOTs because they are awesome . I would use it when I liked coding + animation. For example, create a setter that deals with Number , which displays this number on your web page. When the setter is used, it animates the old number with the new number using tweener . If the starting number is 0, and you set it to 10, you will see that the numbers are quickly flipped from 0 to 10, say, in half a second. Users love this stuff, and it's fun to create.
2. Getters / seters in php
Example from sof
<?php class MyClass { private $firstField; private $secondField; public function __get($property) { if (property_exists($this, $property)) { return $this->$property; } } public function __set($property, $value) { if (property_exists($this, $property)) { $this->$property = $value; } return $this; } } ?>
citings:
Jacksonkr Jan 06 '16 at 16:56 2016-01-06 16:56
source share