Node.JS custom Callback function declare

http://stackoverflow.com/questions/2190850/create-a-custom-callback-in-javascript

421down voteaccepted

Actually, your code will pretty much work as is, just declare your callback as an argument and you can call it directly using the argument name.

The basics

function doSomething(callback) {
    // ...

    // Call the callback
    callback('stuff', 'goes', 'here');
}

function foo(a, b, c) {
    // I'm the callback
    alert(a + " " + b + " " + c);
}

doSomething(foo);

That will call doSomething, which will call foo, which will alert “stuff goes here”.

Note that it’s very important to pass the function reference (foo), rather than calling the function and passing its result (foo()). In your question, you do it properly, but it’s just worth pointing out because it’s a common error.

More advanced stuff

Sometimes you want to call the callback so it sees a specific value for this. You can easily do that with the JavaScript call function:

function Thing(name) {
    this.name = name;
}
Thing.prototype.doSomething = function(callback) {
    // Call our callback, but using our own instance as the context
    callback.call(this);
}

function foo() {
    alert(this.name);
}

var t = new Thing('Joe');
t.doSomething(foo);  // Alerts "Joe" via `foo`

You can also pass arguments:

function Thing(name) {
    this.name = name;
}
Thing.prototype.doSomething = function(callback, salutation) {
    // Call our callback, but using our own instance as the context
    callback.call(this, salutation);
}

function foo(salutation) {
    alert(salutation + " " + this.name);
}

var t = new Thing('Joe');
t.doSomething(foo, 'Hi');  // Alerts "Hi Joe" via `foo`

Sometimes it’s useful to pass the arguments you want to give the callback as an array, rather than individually. You can use apply to do that:

function Thing(name) {
    this.name = name;
}
Thing.prototype.doSomething = function(callback) {
    // Call our callback, but using our own instance as the context
    callback.apply(this, ['Hi', 3, 2, 1]);
}

function foo(salutation, three, two, one) {
    alert(salutation + " " + this.name + " - " + three + " " + two + " " + one);
}

var t = new Thing('Joe');
t.doSomething(foo);  // Alerts "Hi Joe - 3 2 1" via `foo`

It is good practice to make sure the callback is an actual function before attempting to execute it:

if (callback && typeof(callback) === "function") {

  callback();
}

 

My 2 cent. Same but different…

<script>
    dosomething("blaha", function(){
        alert("Yay just like jQuery callbacks!");
    });


    function dosomething(damsg, callback){
        alert(damsg);
        if(typeof callback == "function") 
        callback();
    }
</script>

Mac + Permanent Routing Table on Boot up

http://meinit.nl/add-permanent-static-route-mac-os-x
http://blog.irrashai.com/blog/2009/03/how-to-add-static-route-in-mac-os-x/

http://blog.irrashai.com/blog/2009/03/how-to-add-static-route-in-mac-os-x/

$ sudo mkdir /Library/StartupItems/AddRoute

# cd /Library/StartupItems/AddRoute

$ echo “{

        Description     = \”Add static routing tables\”;

        Provides        = (\”AddRoutes\”);

        Requires        = (\”Network\”);

        OrderPreference = \”None\”;

}” > StartupParameters.plist

$ echo “#!/bin/sh

# Set up static routing tables

# Roark Holz, Thursday, April 6, 2006

. /etc/rc.common

StartService ()

{

        ConsoleMessage “Adding Static Routing Tables”

sudo route add 10.0.0.0/8 192.168.200.15

}

StopService ()

{

        return 0

}

RestartService ()

{

        return 0

}

RunService “$1″” > AddRoutes

$ sudo chmod 755 AddRoutes

Synology & Confluence/Jira

install using installer – easiest  & fastest way to install both.
use PostgreSQL, of course you may use MySQL, but need to modify my.inf to indicate default engine(however, i’m using docker for mysql, but the configuration is not so easy on the container console).
everything are smooth as expected but…

Screen Shot 2016-07-10 at 5.18.14 PM

you should aware it that it consumes too much process power. 96% on installing, 60~70% on posting.

so?
you may use synology for hosting confluence/jira, but cpu will burn…

Synology & Confluence/Jira

install using installer – easiest  & fastest way to install both.
use PostgreSQL, of course you may use MySQL, but need to modify my.inf to indicate default engine(however, i’m using docker for mysql, but the configuration is not so easy on the container console).
everything are smooth as expected but…

Screen Shot 2016-07-10 at 5.18.14 PM

you should aware it that it consumes too much process power. 96% on installing, 60~70% on posting.

so?
you may use synology for hosting confluence/jira, but cpu will burn…