duktape: "TypeError: not callable" - duktape

duk> (function digits(x) { var _x = Math.abs(x); _x = Math.log10(_x); return _x
;} ) (10)
TypeError: not callable
duk_js_call.c:682
digits input:1
global input:1 preventsyield

Math.log10() is not a standard part of Ecmascript E5/E5.1, and is not provided by Duktape.

Related

How to save one of JSON keys, using the method filter()?

I have implemented such a code. I only want to throw one key into the array under the name ("args"). Unfortunately my code returns in line 91 "TypeError: Cannot read properties of undefined (reading 'length')". How to fix it?
All is into async function :)
var objmapPolygon = {}, objmapBsc = {};
let jsonValueBsc = JSON.parse(fs.readFileSync('eventsBsc.json'));
let jsonValuePolygon = JSON.parse(fs.readFileSync('eventsPolygon.json'));
var mapped = jsonValuePolygon.map(
function (v) { for (var l in v) {this[l] = v[l];} },
objmapPolygon
);
console.log(objmapPolygon)
var mapps = jsonValueBsc.map(
function (v) { for (var l in v) {this[l] = v[l];} },
objmapBsc
);
console.log(objmapBsc)
const resultPolygon = mapps.filter(mapp => mapp.length < 7);
console.log(resultPolygon);
The .map() function returns an array filled with the values returned from the callback function. Your jsonValueBsc.map callback function does not return anything, so it is an array of the default return value undefined. When you access those array elements in mapps.filter(mapp => mapp.length < 7), mapp is undefined, thus you get an error.
Return something from the first mapping so there is a value, preferably an array so .length is meaningful.

Cannot read property call of undefined at Blockly.Generator.blockToCode

I am trying to add a custom text block. But when i enter any text in the input field, the error comes up.
"Uncaught TypeError: Cannot read property 'call' of undefined"
Blockly.Blocks['text_input']={
init:function()
{
this.appendDummyInput()
.appendField('Text Input:')
.appendField(new Blockly.FieldTextInput(''),'INPUT');
this.setColour(170);
this.setOutput(true);
}
};
this happens when the language definition for your custom type is missing.
// Replace "JavaScript" with the language you use.
Blockly.JavaScript['text_input'] = function(block) {
var value = Blockly.JSON.valueToCode(block, 'INPUT', Blockly.JavaScript.ORDER_NONE);
// do something useful here
var code = 'var x= "bananas"';
return code;
};

What method do I need to define to implement inspect function in nodejs/v8

I have a C++ class integrated into NodeJS, I would like to change its default object printing
example:
var X = new mypkg.Thing() ;
console.log( X ) ; // prints the object in std way
console.log( X.toString() ) ; // prints Diddle aye day
console.log( '' + X ) ; // prints Diddle aye day
I have defined ToString in the external code, that works. But I want the default printing to be the same.
void WrappedThing::ToString( const v8::FunctionCallbackInfo<v8::Value>& args ) {
Isolate* isolate = args.GetIsolate();
args.GetReturnValue().Set( String::NewFromUtf8( isolate, "Diddle aye day") );
}
Is there an 'Inspect' method to override?
TIA
There is a section on this in the node.js util documentation. Basically you can either expose an inspect() method on the object/class or set the function via the special util.inspect.custom symbol on the object.
Here is one example using the special symbol:
const util = require('util');
const obj = { foo: 'this will not show up in the inspect() output' };
obj[util.inspect.custom] = function(depth, options) {
return { bar: 'baz' };
};
// Prints: "{ bar: 'baz' }"
console.log(util.inspect(obj));

NodeJS - udefined variable in a recursive function call

I have this code that I implemented for a breadth search in a graph,
I putted the variable in an array and I need to call the recursive function
Here is the code sample to fully understand
var completed =[];
var visited = [] ;
var id = 0
function breadth (id) {
completed.push(id);
if (graph[id][1].length > 0){
for (i in graph[id][1]){
node = graph[id][1][i];
id = node.id ;
visited.push (i) ;
breadth(id);
}
}
}
breadth (id) ;
it keep showing this error msg :
if (graph[id][1].length > 0){
^
TypeError: Cannot read property '1' of undefined

How to use _.each as method names for objects in Node.js?

I am new to the underscore library for Node.js and this question has been confusing me. I want to use the value in a key value pair as the first part of an object that I declared earlier, but I keep getting the error
TypeError: Object ax has no method 'push'.
The code that I've been testing on is below.
db_insert = {
first: 'a',
second: 'b'
}
ax = []
ay = []
bx = []
by = []
_.each db_insert, (val, key) ->
db.view key, key, (err, body) ->
unless err
body.rows.forEach (doc) ->
currentTime = newTime doc.id
(val + 'x').push(doc.id)
(val + 'y').push(doc.value)
I've tried with just having
a = []
b = []
_.each db_insert, (val, key) ->
db.view key, key, (err, body) ->
unless err
body.rows.forEach (doc) ->
currentTime = newTime doc.id
val.push(doc.id)
but that doesn't work either.
I'm new to Node.js, underscore so this might be a simple question of escaping, but I feel like when it calls on the (val + 'x') it creates a nested object that's not related to the previously defined array, thus as it hasn't been initialized as an array yet, the type is unknown. However, I may be wrong.
val + 'x' creates a string, so you cannot reference those arrays you previously created. I would recommend using a hashmap (JS object) for this.
var my_arrays = {
'ax' : [],
'ay' : []
// etc.
}
Then, you can do
my_arrays[val + 'x'].push(doc.id)

Resources