Alin Ben Hemo Alin Ben Hemo - 7 months ago 36
Javascript Question

javascript how to create function service ( cunstractor)

in AngularJs if you invoke service function:

app.service('nameService', function(){
this.Service = function (){console.log('hello')}

then you can use this service (object) :
so my question is how i can write function that have 2 arguments (name , function)

function service ( name, function ){
// how angular declare object with that value of first argument ?

i'm ask how to write function like service(name,fn){} ?


you can use bracket notation , to get arguments value .

function service (name, fn){

    var createService = function(){
        return new fn()

    this[arguments[0]] = func()

    //here you can use 'this' because it's function constructor

    this.getLog = function (){


//and you can user it like you  want nameService.getLog() 
//Console: hello