JavaScript uses function to define objects and call Methods
This article mainly introduces how JavaScript uses function to define objects and call methods. Examples of how to define functions in javascript and how to use objects and methods are analyzed. For more information, see
This example describes how JavaScript uses function to define objects and call them. Share it with you for your reference. The specific analysis is as follows:
In JS, you can define an object through a function. The following JS Code defines a movie function object, and then declares an object through the new method, which is also very simple to call.
?
1 2 3 4 5 6 7 8 |
<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 result
?
1 |
Aliens: [object Object] |
I hope this article will help you design javascript programs.