Comments (6)
@JKRhb please see #22 for your answer 👍
from coap-packet.
I forgot to mention that the same goes for optionStringToNumber:
var optionStringToNumber = (function genOptionParser() {
var code = Object.keys(numMap).reduce(function(acc, key) {
acc += 'case \'' + numMap[key] + '\':\n'
acc += ' return \'' + key +'\'\n'
return acc
}, 'switch(string) {\n')
code += 'default:\n'
code += 'return parseInt(string)'
code += '}\n'
return new Function('string', code)
})()
can be replaced with:
var optionStringToNumber = function(string){
for (var key in numMap){
if (numMap.hasOwnProperty(key)){
if (numMap[key] == string){
return key;
}
}
}
return parseInt(string);
}
from coap-packet.
First, I'm very happy to see this used in the browser too!
(Have you tried porting node-coap too?)
Anyway, that technique was used because it's way faster than yours, and in something which is likely used as a server component (like this one) is important.
Are you using Browserify, right? In case, we can move that function into another file, and use the 'browser' field to let browserify pick the correct one.
Would you like to submit a PR that implements that behavior?
from coap-packet.
Yeah, I'm using browserify. node-coap is working fine now. I had to find suitable browserify or chrome ported version of dgram. The current version of dgram I use (chrome-dgram) does not (yet) support IPv6 so I had to comment out anything to do with IPv6. Other than that it's working.
Gotcha. Makes sense.
Sure, I'll submit a PR and and add my "fixes" there.
from coap-packet.
Plus, if you can make it 'safe' to (not) crash when ipv6 is missing it will be great!
from coap-packet.
Revisiting the functions in question I was wondering if creating a switch statement like this is still considered faster or if the use of object literals has catched up in the meantime.
from coap-packet.
Related Issues (6)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from coap-packet.