javascript - What does an Angulars Js factory return? -



javascript - What does an Angulars Js factory return? -

i can't understand how mill returns object of itself.for illustration :

var myapp = angular.module('myapp',[]); myapp.factory('myfactory',function(){ var foo = {}; factory.message = function(){ //do } homecoming foo; });

now,i can phone call factory's methods controller myfactory.message how mill constructor returning object of itself.does have angular's implementation of mill or missing javascript basics here?

this pure javascript functionality.

a new empty literal object beingness created called 'factory' different object. line "var mill = {}" creates object. there can add together functions (methods) on new object e.g. "message".

i haven't played angular while, thing assign new returned object name specified 'myfactory'

the fact variable named mill within function might confusing you. name "foo" or "builder" , work them same.

in response lastly comment see below mill returning instance of "itself"

the mill constructor not returning instance of 'itself'. mill method takes (in case) 2 parameters "name" , function. function returns object (with methods,properties etc.) provide desired functionality.

all mill method on myapp (angular internals) doing assigning 'name' object returned function , making available controllers.

don't hung on thought of angular returning 'factory'. angular needs piece of code (a provider) provides functionality controllers. illustration service created this:

function houdini(){ this.doit = function(){ alert("abracadabra"); }; } myapp.factory("mrmagic", function dosomethinggreat(){ homecoming new houdini() })

later in controller

mrmagic.doit().

javascript angularjs angularjs-service

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -