简体   繁体   中英

AngularJS function () vs function factory() in directive

In angular I've seen directives written both as:

.directive('example', function () {
    // Code
});

.directive('example', function factory() {
    // Code
})

What's the difference between the two?

that is just passing in a named function rather then an anonymous one.

the same way as you can write functions as below:

var foo = function() {
    //function content
}

or

var foo = function foo() {
    //function content
}

function(){..} is an anonymous function.

function foo(){..} is a named function.

There is no difference, otherwise, in functionality. Named functions are better for debugging purposes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM