Home >Web Front-end >JS Tutorial >JavaScript uses functions to define objects and call methods_javascript tips
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.