Skip to main content
added 66 characters in body
Source Link
vivek
  • 298
  • 6
  • 16

I needed this small function for one of my project.

Fetch Attributes

function fetchAttrs(node) {
  
  if (!node || !node.hasAttributes()) return {};
  var attrs = node.attributes;
  var res = {};
  var length = attrs.length;
  for (var i = 0; i < length; i++) {
    var attr = attrs[i];
    res[attr.name] = attr.value;
  }
  return res;
}

It's working fine as expected but I wanted to know if I am missing something from a performance point of view or good coding practices. Just need a second opinion :)

Update

How to handle exceptions, is it a good practice?

I needed this small function for one of my project.

Fetch Attributes

function fetchAttrs(node) {
  
  if (!node || !node.hasAttributes()) return {};
  var attrs = node.attributes;
  var res = {};
  var length = attrs.length;
  for (var i = 0; i < length; i++) {
    var attr = attrs[i];
    res[attr.name] = attr.value;
  }
  return res;
}

It's working fine as expected but I wanted to know if I am missing something from a performance point of view or good coding practices. Just need a second opinion :)

I needed this small function for one of my project.

Fetch Attributes

function fetchAttrs(node) {
  
  if (!node || !node.hasAttributes()) return {};
  var attrs = node.attributes;
  var res = {};
  var length = attrs.length;
  for (var i = 0; i < length; i++) {
    var attr = attrs[i];
    res[attr.name] = attr.value;
  }
  return res;
}

It's working fine as expected but I wanted to know if I am missing something from a performance point of view or good coding practices. Just need a second opinion :)

Update

How to handle exceptions, is it a good practice?

Done.
Source Link
vivek
  • 298
  • 6
  • 16

I needed this small function for one of my project.

Fetch Attributes

function fetchAttrs(node) {
  
  if (!node || !node.hasAttributes()) return {};
  var attrs = node.attributes;
  var res = {};
  var length = attrs.length;
  for (var i = 0; i < length; i++) {
    var attr = attrs[i];
    res[attr.name] = attr.value;
  }
  return res;
}

It's working fine as expected but I wanted to know if I am missing something from a performance point of view or good coding practices. Just need a second opinion :)

I needed this small function for one of my project.

Fetch Attributes

function fetchAttrs(node) {
  
  if (!node || !node.hasAttributes()) return {};
  var attrs = node.attributes;
  var res = {};
  var length = attrs.length;
  for (i = 0; i < length; i++) {
    var attr = attrs[i];
    res[attr.name] = attr.value;
  }
  return res;
}

It's working fine as expected but I wanted to know if I am missing something from a performance point of view or good coding practices. Just need a second opinion :)

I needed this small function for one of my project.

Fetch Attributes

function fetchAttrs(node) {
  
  if (!node || !node.hasAttributes()) return {};
  var attrs = node.attributes;
  var res = {};
  var length = attrs.length;
  for (var i = 0; i < length; i++) {
    var attr = attrs[i];
    res[attr.name] = attr.value;
  }
  return res;
}

It's working fine as expected but I wanted to know if I am missing something from a performance point of view or good coding practices. Just need a second opinion :)

Post Reopened by Jamal
deleted 3 characters in body
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237

I needed this small function for one of my project.

Fetch Attributes

function fetchAttrs(node) {
  
  if (!node || !node.hasAttributes()) return {};
  var attrs = node.attributes;
  var res = {};
  var length = attrs.length;
  for (i = 0; i < length; i++) {
    var attr = attrs[i];
    res[attr.name] = attr.value;
  }
  return res;
}

ItsIt's working fine as expected but I wanted to know if I am missing something from a performance point of view or good coding practices. Just need a second opinion :)

I needed this small function for one of my project.

Fetch Attributes

function fetchAttrs(node) {
  
  if (!node || !node.hasAttributes()) return {};
  var attrs = node.attributes;
  var res = {};
  var length = attrs.length;
  for (i = 0; i < length; i++) {
    var attr = attrs[i];
    res[attr.name] = attr.value;
  }
  return res;
}

Its working fine as expected but I wanted to know if I am missing something from performance point of view or good coding practices. Just need a second opinion :)

I needed this small function for one of my project.

Fetch Attributes

function fetchAttrs(node) {
  
  if (!node || !node.hasAttributes()) return {};
  var attrs = node.attributes;
  var res = {};
  var length = attrs.length;
  for (i = 0; i < length; i++) {
    var attr = attrs[i];
    res[attr.name] = attr.value;
  }
  return res;
}

It's working fine as expected but I wanted to know if I am missing something from a performance point of view or good coding practices. Just need a second opinion :)

added 331 characters in body
Source Link
vivek
  • 298
  • 6
  • 16
Loading
Post Closed as "Not suitable for this site" by Jamal
Source Link
vivek
  • 298
  • 6
  • 16
Loading