I get confused with this JS syntax
var person ={ }
What is it ? Is it an empty array ?
I get confused with this JS syntax
var person ={ }
What is it ? Is it an empty array ?
Initialize object
It’s an empty object that you can add properties to.
var person = {}
person.name = 'winzip'
console.log(person)
Can I add function as a property ? Can that function return another object ?
yes.
person.getNewPerson = function() {
return { name: 'bob' }
}
var person2 = person.getNewPerson()
console.log(person2.name)
got this part.
Is it possible that function returns the same object where it has been added ?
Sorry, I don’t understand what you’re asking.
Ok… please see this code.
var myApp=angular.module(“myApp”,)
angular is a global object defined in angular JS library. // similar to our person object
module is a function added to angular object // similar to our getNewPerson function in person object
Now , my question is what module function returns ? does it return the same angulr object or a different object ?
Angular JS lib: https://code.angularjs.org/1.3.0-rc.1/angular.js
Ah ok, there’s no way to know what a function returns from just looking at the way it’s called.
myApp
may be a function, an object, a number etc…
The only way is to log it out and see or to look at the code.
It appears to be a new object in this case.
sorry…I posted late … I just don’t find the module function return type in this Lib: https://code.angularjs.org/1.3.0-rc.1/angular.js
It appears to be a new object in this case.
empty object ?
Honestly, I wouldn’t worry about trying to read the angular source at this stage. It’s not important, just understand how to use the framework.
var myApp=angular.module("myApp",[])
console.log(myApp)
got your point…thanks
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.