合同小程序前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.1 KiB

  1. // @ts-nocheck
  2. /**
  3. *
  4. * @param obj
  5. * @param key
  6. * @returns truefalse
  7. */
  8. function hasOwn(obj: UTSJSONObject, key: string): boolean
  9. function hasOwn(obj: Map<string, unknown>, key: string): boolean
  10. function hasOwn(obj: any, key: string): boolean {
  11. if(obj instanceof UTSJSONObject){
  12. return obj[key] != null
  13. }
  14. if(obj instanceof Map<string, unknown>){
  15. return (obj as Map<string, unknown>).has(key)
  16. }
  17. return false
  18. }
  19. export {
  20. hasOwn
  21. }
  22. // 示例
  23. // const obj = { name: 'John', age: 30 };
  24. // if (hasOwn(obj, 'name')) {
  25. // console.log("对象具有 'name' 属性");
  26. // } else {
  27. // console.log("对象不具有 'name' 属性");
  28. // }
  29. // // 输出: 对象具有 'name' 属性
  30. // const arr = [1, 2, 3];
  31. // if (hasOwn(arr, 'length')) {
  32. // console.log("数组具有 'length' 属性");
  33. // } else {
  34. // console.log("数组不具有 'length' 属性");
  35. // }
  36. // 输出: 数组具有 'length' 属性