Showing posts with label custome method using javascript. Show all posts
Showing posts with label custome method using javascript. Show all posts

Saturday, August 23, 2025

Custom method using prototype in JavaScript.

<!DOCTYPE html>

<html>

<head>

  <title>Custom Prototype Method</title>

</head>

<body>

  <h2>Prototype Sum Method</h2>

  <button onclick="calculate()">Click to Calculate</button>


  <script>

    // ✅ Add custom method using prototype

    Number.prototype.add = function(num) {

      return this + num;

    };


    function calculate() {

      let result = (10).add(20); // using custom method

      alert("The sum is: " + result);

    }

  </script>

</body>

</html>


Custom method using prototype in JavaScript.

<!DOCTYPE html> <html> <head>   <title>Custom Prototype Method</title> </head> <body>   <h2>...