Setter getter closure functions
How do I make an setter getter closure functions?
To set and get i'm gonna use a closure, do not pollute the global scope with variables. lets do it!. What is a setter getter closure functions? How do you make a setter getter closure functions? This script and codes were developed by Paul on 27 October 2022, Thursday.
Setter getter closure functions - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>setter getter closure functions</title>
</head>
<body> <script src="js/index.js"></script>
</body>
</html>
Setter getter closure functions - Script Codes JS Codes
function makeP(o, name, prd)
{ var wert; var age; //getter o["get"+ name ] = function(){return wert;}; o["get"+ age] = function(){return age;}; //setter //verzweigung o["set" + name] = function(v) { if(prd && !prd(v)) throw "set"+name+": ungültiger Wert"+v; else wert = v; }; o["set" + age] = function(v) { if(prd && !prd(v)) throw "set"+age+": ungültiger Wert"+v; else wert = v; };
}
var o = {};
makeP(o, "Name", function(x){return typeof x == "string";});
makeP(o, "Age", function(x){return typeof x == "number";});
o.setName("Frank");
console.log(o.getName());
//teste error handling
//o.setName(0);
o.setAge(20);
console.log(o.getAge());
Developer | Paul |
Username | paulq |
Uploaded | October 27, 2022 |
Rating | 3 |
Size | 1,662 Kb |
Views | 10,120 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Drag in vanilla js using dotval math instead of translate | 2,662 Kb |
Parallax on scrollevent | 2,386 Kb |
Three js | 2,353 Kb |
Callback function | 2,939 Kb |
Flexbox-Slider-Test | 1,666 Kb |
Canvas tutorial | 2,043 Kb |
Sitemap getter | 1,823 Kb |
Dropdow | 2,466 Kb |
Sticky header | 2,309 Kb |
Input tabcontainer | 4,390 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
IbrahimJabbari-Effect14 | Ibrahimjabbari | 1,919 Kb |
Wikipedia Viewer | Codinger | 4,681 Kb |
Motion Lines - codevember - 02 - 2016 | Caiocares | 2,744 Kb |
Pure CSS Spinners | Jlong | 2,043 Kb |
Nice textured background | Hans | 2,659 Kb |
Placeholder support for contentEditable elements, without JavaScript | Flesler | 1,863 Kb |
Filtering with shuffle.js | Deyand | 2,712 Kb |
Simple Carousel Pure CSS | Dangvanthanh | 4,080 Kb |
JS Countdown Timer | Ayoungh | 2,435 Kb |
Nested table email layout | Massimo-cassandro | 2,355 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!