auto skip function args
https://repl.it/@xgqfrms/auto-skip-function-args
"use strict";
/**
*
* @author xgqfrms
* @license MIT
* @copyright xgqfrms
* @created 2019-09-28
* @modified
*
* @description auto skip function args that not actually used
* @description Automatically skip parameters that are not actually used by the function
* @description 自动跳过函数实际上没有使用的参数
* @augments
* @example
* @link
*
*/
let log = console.log;
// this OK
const autoSkipArgs = (fn, skipArgsNumber, args) => {
fn.apply(this, Array(skipArgsNumber).concat([args]));
}
// function autoSkipArgs(fn, skipArgsNumber, args) {
// fn.apply(this, Array(skipArgsNumber).concat([args]));
// }
export default autoSkipArgs;
export {
autoSkipArgs,
};
// testing
/*
let log = console.log;
const func = (arg1 = ``, arg2 = {}) => {
log(`arg1`, arg1);
log(`arg2`, arg2);
};
let obj = {
key: 1,
value: "A",
};
autoSkipArgs(func, 1, obj);
// arg1
// arg2 { key: 1, value: 'A' }
*/
array & empty bug
Uint8Array
new Uint8Array(2).map(i => "");
// Uint8Array(2) [0, 0]
new Uint8Array(2);
// Uint8Array(2) [0, 0]
[...new Uint8Array(2).map(i => "")]
// (2) [0, 0]
[...new Uint8Array(2)].map(i => "");
// (2) ["", ""]
site: www.stackoverflow.com js function ignore first arguments
https://stackoverflow.com/questions/32518615/skip-arguments-in-a-javascript-function
https://stackoverflow.com/questions/25642690/javascript-skip-arguments-in-function-call
https://stackoverflow.com/questions/38224231/how-to-remove-the-first-argument-of-function
shit antd & table col render
https://ant.design/components/table-cn/#Column
render(text, record, index)
https://codesandbox.io/s/antd-table-auto-skip-args-j1vu2
import React from "react";
import ReactDOM from "react-dom";
import "antd/dist/antd.css";
import "./index.css";
import { Table, Badge, Menu, Dropdown, Icon } from "antd";
const menu = (
<Menu>
<Menu.Item>Action 1</Menu.Item>
<Menu.Item>Action 2</Menu.Item>
</Menu>
);
let log = console.log;
function NestedTable() {
const columns = [
{ title: "Name", dataIndex: "name", key: "name" },
{ title: "Platform", dataIndex: "platform", key: "platform" },
{ title: "Version", dataIndex: "version", key: "version" },
{ title: "Upgraded", dataIndex: "upgradeNum", key: "upgradeNum" },
{
title: "Creator",
dataIndex: "creator",
key: "creator",
// render: (undefined, undefined, index) => {
// render: ("", "", index) => {
// render: ("x", "x", index) => {
render: (a, b, index) => {
log(`index`, index);
return <span>auto sikp args</span>;
}
},
{
title: "Date",
dataIndex: "createdAt",
key: "createdAt",
render: (text, record, index) => {
log(`text`, text, index);
// log(`record`, record);
return <span>{text}</span>;
}
},
{
title: "Action",
key: "operation",
render: (record, index) => {
// log(`record`, record, index);
return <a>Publish</a>;
}
}
];
const data = [];
for (let i = 0; i < 3; ++i) {
data.push({
key: i,
name: "Screem",
platform: "iOS",
version: "10.3.4.5654",
upgradeNum: 500,
creator: "Jack",
createdAt: "2014-12-24 23:12:00"
});
}
return (
<Table
className="components-table-demo-nested"
columns={columns}
dataSource={data}
/>
);
}
ReactDOM.render(<NestedTable />, document.getElementById("container"));
anonymous function args bug ???
(...[...new Uint8Array(2)].map(i => ""), 123) => {
console.log(arguments[0]);
};
// Uncaught SyntaxError: Unexpected token '...'
copy(...[...new Uint8Array(2)].map(i => ""));
// undefined
arrow function & arguments bug
function abc(arg1, arg2) {
console.log(arguments[0]);
}
abc(...[...new Uint8Array(2)].map(i => ""), 123);
const f = (arg1, arg2) => {
console.log(arguments[0]);
};
f(...[...new Uint8Array(2)].map(i => ""), 123);
// VM769:2 Uncaught ReferenceError: arguments is not defined