application和concat在下面的nodejs函数中意味着什么,以及如何使用它



如何理解下面代码中的apply和concat。我查看https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concatconcat语法是const new_array=old_array.concat([value1[,value2[,…[,valueN]]](参数。但0和最后一个括号((的用途是什么

return extend.apply(undefined, [methodTxObject].concat((0, _toConsumableArray3.default)(extendArgs)));
var ContractFactory = function ContractFactory(extend) {
return function (contractABI) {
var output = {};
output.at = function atContract(address) {
function Contract() {
var self = this;
self.abi = contractABI || [];
self.address = address || '0x';
getCallableMethodsFromABI(contractABI).forEach(function (methodObject) {
self[methodObject.name] = function contractMethod() {
if (methodObject.constant === true) {
throw new Error('A call does not return the txobject, no transaction necessary.');
}
if (methodObject.type === 'event') {
throw new Error('An event does not return the txobject, events not supported');
}
var providedTxObject = {};
var methodArgs = [].slice.call(arguments);
if (methodObject.type === 'function') {
if (hasTransactionObject(methodArgs)) providedTxObject = methodArgs.pop();
var methodTxObject = (0, _assign2.default)({}, providedTxObject, {
to: self.address
});
methodTxObject.function = encodeMethodReadable(methodObject, methodArgs);
if (!extend) return methodTxObject;
var extendArgs = methodArgs.slice(methodObject.inputs.length);
return extend.apply(undefined, [methodTxObject].concat((0, _toConsumableArray3.default)(extendArgs)));
}
};
});
}
return new Contract();
};
return output;
};
};

包含函数的对象/数组。这只是一种不同的通话方式CCD_ 1。不需要assigning然后调用,只需获取并调用immediate即可。

const object = {
fn: function(name) {
console.log("My name is: " + name)
}
}
const fn = object["fn"]
fn("Slim Sheddy") // one way of calling
// OR:
object["fn"]("Slim Sheddy") // other way of calling

我不理解(0, _fn)命名法的用途,但这只是一个函数调用。"0,"部分以某种方式更改了"this",然后使用参数调用逗号后的函数。基本上是这样的:

var append = (0, _toConsumableArray3.default)(extendArgs)
// -> something like: _toConsumableArray3.default.call(0?, extendArgs)
var args = [methodTxObject].concat(append)
return extend.apply(undefined, args);

这可能是避免原型继承的一种方法。参见:

> (0,console.log)('test')
test
> (console.log)('test')
test
> (Object.toString)('test')
'function Object() { [native code] }'
> (0,Object.toString)('test')
Thrown:
TypeError: Function.prototype.toString requires that 'this' be a Function
at toString (<anonymous>)

相关内容

最新更新