runeveryday
runeveryday

Reputation: 2799

javascript----OOP

 var  changeUrl={
                'baseUrl':...,
                ......,
                'getDomain' : function(url){
                       .......
       }
                'InitWebLink':function(){
          }
     }

 changeUrl.InitWebLink();

the above is a code part structure. but i don't understand it well and don't know each line's aim. expect someone can explain it for me. thank you.

Upvotes: 1

Views: 204

Answers (3)

Crozin
Crozin

Reputation: 44376

That's a object literal which defines an object with members: baseUrl, getDomain and InitWebLink. Object's members can be accessed using dot-notation, or array-notation: object.member, object["member"], so calling changeUrl.InitWebLink(); you're involving a method of the object.

If you declare an object using literal then every member can be treated as public, static in traditional class-based OOP.

Upvotes: 0

decyclone
decyclone

Reputation: 30830

In JavaScript, every object acts like a dictionary.

in the code given changeUrl is initialized with 3 members:

  • baseUrl - unknown type
  • getDomain and InitWebLink are both methods (function() declaration)

The code follows JavaScript Object Notation

References : JSON (MSDN) and JSON (Wikipedia)

Upvotes: 2

escargot agile
escargot agile

Reputation: 22389

It's a definition of an object. changeUrl is an object with several member fields and member functions (methods). baseUrl is a field, while getDomain(url) and InitWebLink() are methods which are implemented in place.

Upvotes: 0

Related Questions