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
Release: 2016-05-16 16:08:05
Original
1145 people have browsed it

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>
Copy after login

Output results

aliens:[object Object]
Copy after login

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

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template