prototype





js/script.js
  • function objOne(arg0, arg1) {
  •  this.val = arg0;
  •  this.str = arg1;
  • }
  •  
  • function funMake() {
  •  var O = new objOne(5, 'Hello World!');
  •  objOne.prototype.fun = function() {
  •   for(var i=0; i<this.val; i++) {
  •    document.write(this.str + '<br />');
  •   }
  •  }
  •  O.fun();
  • }
  • function objOne(arg0, arg1) {
  •  this.val = arg0;
  •  this.str = arg1;
  • }
  •  
  • function funMake() {
  •  var O = new objOne(5, 'Hello World!');
  •  objOne.prototype.fun = function() {
  •   for(var i=0; i<this.val; i++) {
  •    document.write(this.str + '<br />');
  •   }
  •  }
  •  O.fun();
  • }


index.html
  • <!DOCTYPE html>
  • <html>
  • <head>
  •  <meta charset="utf-8" />
  •  <title>New Page</title>
  •  <script src="js/script.js"></script>
  • </head>
  • <body>
  • <script>
  •  funMake();
  • </script>
  • </body>
  • </html>
  • <!DOCTYPE html>
  • <html>
  • <head>
  •  <meta charset="utf-8" />
  •  <title>New Page</title>
  •  <script src="js/script.js"></script>
  • </head>
  • <body>
  • <script>
  •  funMake();
  • </script>
  • </body>
  • </html>