Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xyzdata/77f802a3a7744c85cf117d3666c85e9d to your computer and use it in GitHub Desktop.
Save xyzdata/77f802a3a7744c85cf117d3666c85e9d to your computer and use it in GitHub Desktop.
xgqfrms , react & e.preventDefault(); & e.stopPropagation();

react & e.preventDefault(); & e.stopPropagation();

xgqfrms react

    


e.preventDefault();
e.stopPropagation();
e.nativeEvent.stopImmediatePropagation();

ant-design/ant-design#6576

@xyzdata
Copy link
Author

xyzdata commented Aug 2, 2017

Global_Objects

Object.keys() & Array.some()

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys

Object.keys() 方法会返回一个由一个给定对象的自身可枚举属性组成的数组
数组中属性名的排列顺序和使用 for...in 循环遍历该对象时返回的顺序一致
(两者的主要区别是 一个 for-in 循环还会枚举其原型链上的属性)。

https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/some

some() 方法测试数组中的某些元素是否通过由提供的函数实现的测试。

/**
 * 
 * @param {function} fieldsError 
 * @returns boolean
 * 
 * @demo: hasErrors(getFieldsError())
 * 
 */
function hasErrors(fieldsError) {
    return(
        Object
        .keys(fieldsError)
        .some(
            (field) => (fieldsError[field])
        )
    );
}

@xyzdata
Copy link
Author

xyzdata commented Aug 2, 2017

/* Array 对象 */ 
let arr = ["a", "b", "c"];

console.log(Object.keys(arr)); 
// "0,1,2"

/* 类数组 对象 */ 
let obj = { 0 : "a", 1 : "b", 2 : "c"};

console.log(Object.keys(obj)); 
// "0,1,2"

// 类数组 对象, 随机 key 排序 
let anObj = { 100: 'a', 2: 'b', 7: 'c' }; 

console.log(Object.keys(anObj)); 
// ['2', '7', '100']


/* Object 对象 */ 

let abc = {a: "a", b: "b", c: "c"}; 

console.log(Object.keys(abc)); 
// (3) ["a", "b", "c"] 

let xyz = {x: "xxx", y: "yyy", z: "zzz"}; 

console.log(Object.keys(xyz)); 
// (3) ["x", "y", "z"]


image

@xyzdata
Copy link
Author

xyzdata commented Aug 2, 2017

Object.keys()

https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Object/keys

Object.keys(obj) / Object.keys(arr)

let abc = {a: "a", b: "b", c: "c"};
console.log(Object.keys(abc));
// (3) ["a", "b", "c"]

let xyz = {x: "xxx", y: "yyy", z: "zzz"};
console.log(Object.keys(xyz));
// (3) ["x", "y", "z"]


// array like object with random key ordering
let anObj = { 100: 'a', 2: 'b', 7: 'c' };
console.log(Object.keys(anObj)); 
// ['2', '7', '100']


// 类数组 对象, 随机 key 排序 
let anObj = { 100: 'a', 2: 'b', 7: 'c' }; 

console.log(Object.keys(anObj)); 
// ['2', '7', '100']


/* getFoo 是个不可枚举的属性 */ 

let my_obj = Object.create(
    {}, 
    {
        getFoo: {
            value: function() {return this.foo;}
        }
    }
);

my_obj.foo = 1;

console.log(Object.keys(my_obj)); 
// ["foo"]

console.log(my_obj);
// {foo: 1, getFoo: ƒ}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment