1

I'm playing around with bind, and the following works:

webSQL.InsertTransaction = function(qry,CurrentRow) {
    var local = {};
    // Clone the webSQL.Insert function and add 2 parameters:
    local.InsertTransaction = webSQL.Insert.bind(this,qry,CurrentRow);
    // Call webSQL.Insert(qry,CurrentRow,Transaction)
    dbo.transaction(local.InsertTransaction);
}
webSQL.Insert = function(qry,CurrentRow,Transaction) {}

I'd like to simplify it even more. Can I somehow not have to specify the 2 variables that are in the arguments scope, but instead do something like:

local.InsertTransaction = webSQL.Insert.bind(webSQL.InsertTransaction)

maybe. My thinking is that then webSQL.Insert can reference qry and CurrentRow from it's "this.arguments" thingy.

4

1 回答 1

2

I'm not sure why you were using the object assigned to the local variable in the first place.

All you were doing was giving it a function, and then taking that function right back out. Why not skip that step?

webSQL.InsertTransaction = function(qry,CurrentRow) {
    dbo.transaction(webSQL.Insert.bind(this,qry,CurrentRow));
}
于 2013-03-31T00:37:04.253 回答