Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Prototype object for math operations
- const MathOperations = {
- // Method to add two numbers
- add(x, y) {
- return x + y;
- },
- // Method to subtract two numbers
- subtract(x, y) {
- return x - y;
- }
- };
- // Specific object representing a number value
- const NumberValue = {
- value: 0
- };
- // Delegate math operations to the MathOperations prototype methods
- NumberValue.__proto__ = MathOperations;
- // Test math operations
- const number1 = Object.create(NumberValue);
- number1.value = 10;
- const number2 = Object.create(NumberValue);
- number2.value = 5;
- console.log(number1.add(5, 3)); // Output: 8
- console.log(number2.subtract(10, 3)); // Output: 7
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement