MarkLogic: fn.empty fn.exsits !== null !== ""
MarkLogic: fn.empty fn.exsits !== null !== ""
为了确定 cts.search returns 是否为有效文件,以下语句的最终区别是什么?
1. if (!fn.empty(acctDoc)) {....}
2. if (!fn.exists(acctDoc)) {....}
3. if (acctDoc !== null || acctDoc !== "") {...}
我的经验是,No.3各方面都不错。
if (!fn.empty(acctDoc)) {....}
Return 如果 acctDoc
不是 空序列 ,则为真。
if (!fn.exists(acctDoc)) {....}
Return 如果 acctDoc
是一个空序列 . 则为真
if (acctDoc !== null || acctDoc !== "") {...}
Return 如果 acctDoc
不是 null
或者它不是空字符串,则为真。
If the value of $arg is the empty sequence, the function returns true; otherwise, the function returns false.
If the value of $arg is not the empty sequence, the function returns true; otherwise, the function returns false.
使用这个测试函数:
function test(acctDoc) {
const results = [];
if (!fn.empty(acctDoc)) { results.push("not empty") };
if (!fn.exists(acctDoc)) { results.push("does not exist") };
if (acctDoc !== null || acctDoc !== "") { results.push("not null or is not empty string") };
return results;
}
test("test")
returns ["not empty", "not null or is not empty string"]
test("")
returns ["not empty", "not null or is not empty string"]
test(null)
returns ["does not exist", "not null or is not empty string"]
test(fn.head(fn.doc()))
returns ["not empty", "not null or is not empty string"]
test(fn.doc(fn.string(xdmp.random())))
returns ["does not exist", "not null or is not empty string"]
为了确定 cts.search returns 是否为有效文件,以下语句的最终区别是什么?
1. if (!fn.empty(acctDoc)) {....}
2. if (!fn.exists(acctDoc)) {....}
3. if (acctDoc !== null || acctDoc !== "") {...}
我的经验是,No.3各方面都不错。
if (!fn.empty(acctDoc)) {....}
Return 如果acctDoc
不是 空序列 ,则为真。if (!fn.exists(acctDoc)) {....}
Return 如果acctDoc
是一个空序列 . 则为真
if (acctDoc !== null || acctDoc !== "") {...}
Return 如果acctDoc
不是null
或者它不是空字符串,则为真。
If the value of $arg is the empty sequence, the function returns true; otherwise, the function returns false.
If the value of $arg is not the empty sequence, the function returns true; otherwise, the function returns false.
使用这个测试函数:
function test(acctDoc) {
const results = [];
if (!fn.empty(acctDoc)) { results.push("not empty") };
if (!fn.exists(acctDoc)) { results.push("does not exist") };
if (acctDoc !== null || acctDoc !== "") { results.push("not null or is not empty string") };
return results;
}
test("test")
returns["not empty", "not null or is not empty string"]
test("")
returns["not empty", "not null or is not empty string"]
test(null)
returns["does not exist", "not null or is not empty string"]
test(fn.head(fn.doc()))
returns["not empty", "not null or is not empty string"]
test(fn.doc(fn.string(xdmp.random())))
returns["does not exist", "not null or is not empty string"]