JavaScript USES function to define objects and invoke methods

  • 2020-05-17 04:49:39
  • OfStack

This article demonstrates how JavaScript USES function to define objects and invoke methods. Share with you for your reference. The specific analysis is as follows:

In JS, you can define objects by function. The following JS code defines an movie function object, and then declares the object by new method, which is also very simple to call.


<script type="text/javascript">
function movie(title, director) {
  this.title = title;
  this.director = director;
  }
var aliens = new movie("Aliens","Cameron");
document.write("aliens:"+aliens.toString());
</script>

The output


aliens:[object Object]

I hope this article is helpful for you to design javascript program.


Related articles: