Home >Web Front-end >JS Tutorial >JavaScript uses functions to define objects and call methods_javascript tips

JavaScript uses functions to define objects and call methods_javascript tips

WBOY
WBOYOriginal
2016-05-16 16:08:051148browse

The examples in this article describe how JavaScript uses functions to define objects and call them. Share it with everyone for your reference. The specific analysis is as follows:

In JS, you can define objects through functions. The following JS code defines a movie function object, and then declares the object through the new method. It 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>

Output results

aliens:[object Object]

I hope this article will be helpful to everyone’s JavaScript programming design.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn