Content deleted Content added
→Inheritance: Improved formatting for better rendering on mobile version. Tags: Mobile edit Mobile web edit |
→Methods: Improved formatting for better rendering. Tags: Mobile edit Mobile web edit |
||
Line 1,242:
A [[method (computer science)|method]] is simply a function that has been assigned to a property name of an object. Unlike many object-oriented languages, there is no distinction between a function definition and a method definition in object-related JavaScript. Rather, the distinction occurs during function calling; a function can be called as a method.
When called as a method, the standard local variable ''
In the example below, Foo is being used as a constructor. There is nothing special about a constructor - it is just a plain function that initialises an object. When used with the ''
Note that in the example below, Foo is simply assigning values to slots, some of which are functions. Thus it can assign different functions to different instances. There is no prototyping in this example.
|