lang
stringclasses
4 values
desc
stringlengths
2
8.98k
code
stringlengths
7
36.2k
title
stringlengths
12
162
JS
This question is particularly pointed at other C # devs coming over to TypeScript in VS Code.I fell in love with the code completion in VS C # . To illustrate , say I 'm trying to write : Using C # , I would have : type `` con '' a list of suggestions would appear , probably starting with `` console '' since that 's hi...
console.log ( 'hello ' )
Can VS Code code completion be configured to accept a suggestion on punctuation ?
JS
I have a problem when I try to overwrite a file with gulp . To make you understand my problem here 's an example of what I am trying to do : My project file path : Copy the base source to dist.Copy the custom client source and overwrite what 's in the dist folder.What am I doingThe actual problemThe problem is that the...
- Project |- clients |- clientBase |- JS |- jsexample.js |- jsexample2.js |- CSS |- HTML |- client1 |- JS |- jsexample2.js |-dist const args = require ( 'yargs ' ) .argv ; const src = { base : './Project/clients/clientBase ' , client : ` ./Project/clients/ $ { args.client } ` , } ; const dist = './Project/dist ' ; cons...
Gulp is not overwriting JS files
JS
I have a test that is comparing two sets , and when it fails the output is of the form : I find this very hard to read as it 's just a text diff and the real discrepancy is obscured ( the sets differ by 2 elements but the output makes it hard to tell which ) This is an app I created via create-react-app , and I 'm runn...
- Expected + Received Set { Position { `` x '' : 0 , - `` y '' : 0 , + `` y '' : 2 , } , Position { - `` x '' : 1 , - `` y '' : 1 , + `` x '' : 0 , + `` y '' : 0 , } , Position { - `` x '' : 2 , + `` x '' : 1 , `` y '' : 1 , } , Position { - `` x '' : 2 , - `` y '' : 0 , + `` x '' : 1 , + `` y '' : 2 , } , } test ( 'ca...
show entire output of expected and received in failed test
JS
I am working on a parallel coordinates graph with d3.js and I am trying to plot some multiple dimensional data from an external json file.This is how the data in the json file is structured : And this is how so far I am handling the domain and how the graph plots the items data : The console does not give me any type o...
[ { `` timestamp '' : 1437571117.035159 , `` dimension '' : 10 , `` value '' : [ { `` value '' : 0.13347661474528993 , `` label '' : `` A '' } , { `` value '' : 0.8677079004784608 , `` label '' : `` B '' } , { `` value '' : 0.7757451827314333 , `` label '' : `` C '' } , { `` value '' : 0.9614725817942508 , `` label '' ...
Parallel coordinates multidimensional data not visualised in D3
JS
In JavaScript you can compose objects using some kind of extend function . For example I might have an observable class that exposes a set of public methods ( get , push , set , increment , get , etc ) In this case the observable also happens to be an EventEmitter so it also exposes a further set of public methods ( em...
var Model = extend ( { } , Observable , { constructor : function ( ) { // Oops , I was supposed to know Observable uses the _state name already this._state = { ... } } , someMethod : function ( ) { ... } } )
How to avoid name clashes when composing objects
JS
Number ( ) function returns incorrect values on some arguments , like this : I tested this on Firefox , Chome , IE and Node.js . Why is this happening ?
Number ( '10000000712224641 ' ) returns 10000000712224640Number ( '10000000544563531 ' ) returns 10000000544563532
Why does Number ( ) return wrong values with very large integers ?
JS
I use iron-list from google Polymer . I kwon you can use Polymer.IronA11yKeysBehavior but even with the example I have no idea how I add it in JavaScript to my iron-list.Using Vaadin Polymer GWT lib . In this lib you have When I check the current values of the key bindings I defined a print function to log a variable t...
< iron-list items= '' [ [ data ] ] '' as= '' item '' > < template > < div tabindex $ = '' [ [ tabIndex ] ] '' > Name : [ [ item.name ] ] < /div > < /template > < /iron-list > IronList list ; list.setKeyBindings ( ? ? ? ) ; // do n't know how to use this functionlist.setKeyEventTarget ( ? ? ? ? ) ; // do n't know how to...
Handle Keyboard events for iron-list in GWT ?
JS
On my website I do n't want to bundle but instead use ES6 modules directly ( works for the audience ) I try importing fabric.js byimport { fabric } from `` ../node_modules/fabric/dist/fabric.js '' ; like I do when I bundle ( for bundles it works fine ) .however when starting the website I get `` Uncaught SyntaxError : ...
< ! DOCTYPE html > < html > < head > < meta charset= '' utf-8 '' > < script type= '' module '' src= '' ./start.js '' > < /script > < /head > < body > < /body > < /html >
fabric js as ES6 import in Chrome does n't work
JS
I am having a slight issue with using dragabilly in angular , the problem is odd because it was working until I made some changes to how the content using packery is loaded in , specifically adding a level of nested repeats . When I do this , packery still runs correctly , however it seems dragabilly only runs on the f...
< div class= '' item gs-w '' ng-class= '' widget.size '' ng-repeat= '' widget in contentHere '' packery-angular > < ! -- nested repeat -- > < div ng-repeat= '' side in widget.sides '' ng-show= '' side.active '' > var draggable2 = new Draggabilly ( element [ 0 ] , { handle : '.handle ' } ) ; var draggable2 = new Draggab...
angular , nested repeat breaking directive ( packery + dragabilly )
JS
I have already gone through the thread Any difference between await Promise.all ( ) and multiple await ? , so I am clear about Promise.all and multiple awaits.Still , I am not very clear about the below 2 scenarios.In Case 1 why does it execute sequentially ( takes 10s ) whereas in Case 2 it executes in parallel ( take...
function promiseWait ( time ) { return new Promise ( ( resolve , reject ) = > { setTimeout ( ( ) = > { resolve ( true ) ; } , time ) ; } ) ; } async function test1 ( ) { var t0 = performance.now ( ) var a = await promiseWait ( 1000 ) var b = await promiseWait ( 2000 ) var c = await promiseWait ( 3000 ) var d = await pr...
What makes ` async/await ` statements run sequentially vs in parallel in ES6 ?
JS
The StoryWe 've been using Protractor framework extensively and have established a rather large test codebase . We 've also been following the Page Object pattern to organize our tests.Recently , we 've started to use the Galen framework to fill the gap of visual/layout/responsive design testing . We really like the fr...
var LoginPage = function ( ) { this.username = element ( by.id ( `` username '' ) ) ; this.password = element ( by.id ( `` password '' ) ) ; this.loginButton = element ( by.binding ( `` buttonText '' ) ) ; } ; module.exports = new LoginPage ( ) ; this.LoginPage = $ page ( `` Login page '' , { username : ' # username ' ...
Combining Galen and Protractor frameworks
JS
I 've heard that using global variable is bad in JavaScript . Since let is block-scoped can I use it within a block that includes all other functions and use it in a similar way to global variables ?
{ var b = 10 ; let c = 20 ; function foo ( ) { return c ; } }
Using let variable instead of using Global variables
JS
As we all know , we can define functions with and without a name : Where foo 's function has n't got it 's own name , but bar does.Is it possible to define the name of a function after defining it ? So doing something makes console.log ( foo.name ) return something else than ``
var/let/const foo = function ( ) { } function bar ( ) { } console.log ( foo.name ) -- > `` console.log ( bar.name ) -- > 'bar '
Set function name after defining it
JS
In JavaScript , I noticed that the ES6 for ... of loop has a much different performance than the traditional for ( start ; stop ; step ) loop.BenchmarkResults ( Tested using Node.js v10.11.0 ) As you can see , as n increases , the speed of the for-of loop decreases at a faster rate than the standard for loop . Why is t...
const n = 10000 ; const arr = Array ( n ) .fill ( ) .map ( ( e , i ) = > i ) ; // [ 0 , n ) console.log ( ' n = ' , n ) ; let sum1 = 0 ; console.time ( 'for let i ' ) ; for ( let i = 0 ; i < arr.length ; i++ ) { sum1 += arr [ i ] ; } console.timeEnd ( 'for let i ' ) ; let sum2 = 0 ; console.time ( 'for of ' ) ; for ( l...
Why is for-of loop faster than standard for loop for small arrays and slower for larger arrays ?
JS
Most DOM query methods are available on both Documents and Elements . For example , However , getElementById is only available on Document : Why is this so ? The WHATWG DOM Living Standard tells us that : Web compatibility prevents the getElementById ( ) method from being exposed on elementsThe W3C DOM4 Recommendation ...
console.assert ( document.getElementsByTagName & & document.body.getElementsByTagName & & document.getElementsByClassName & & document.body.getElementsByClassName & & document.querySelector & & document.body.querySelector & & document.querySelectorAll & & document.body.querySelectorAll ) ; console.assert ( document.get...
Why is n't getElementById ( ) available on Elements ?
JS
I 'm using flow to annotate types in my code.Is there any way to teach flow to report a warning or an error for comparisons with non matching types ( string in my case ) ? here is the example for testedit : so it seems not to be possible to do it with enums . but , since this is actually an error I encountered , I 'd l...
type Bar = 'One ' | 'Two ' ; function foo ( b : Bar ) : boolean { return b === 'Three ' ; }
Comparing enum values in Flow
JS
I 'm working with a project nuxt.js , I need to run a shell script on every changed file , that is , every webpack build.so I 'm using the Webpack HooksI created my Webpack Plugin/plugins/NamedExports.jsplugins/shell.jsthis script is to make named exports within each folder in the component directory , examplecomponent...
const pluginName = 'NamedExports'const { exec } = require ( 'child_process ' ) class NamedExports { apply ( compiler ) { compiler.hooks.beforeCompile.tap ( pluginName , ( params , callback ) = > { exec ( 'sh plugins/shell.sh ' , ( err , stdout , stderr ) = > { console.log ( stdout ) console.log ( stderr ) } ) } ) } } e...
how to break loop in webpack hook
JS
My question is quite similar to What is the purpose of a self executing function in javascript ? , however it concerns userscripts ( specifically for GreaseMonkey ) instead.I see that some userscripts are distributed with this pattern , and some are not.Example of script with the IIFE pattern : ( source ) Example of sc...
// ==UserScript==// ( ... ) // ==/UserScript== ( function ( ) { // if < condition > document.location.href += ' ? sk=h_chr ' ; // ... } ) ( ) ; // ==UserScript==// ( ... ) // ==/UserScript==window.location.href = `` https : //www.facebook.com/ ? sk=h_chr '' ;
Is the Immediately-Invoked Function Expression ( IIFE ) pattern really necessary when writing userscripts ?
JS
I have the following problem , my function accepts an array that contains 4 arrays , each element is a number . The functions must return the largest element of each array . Results : Apparently it works , but when I tried with the last array [ 1000 , 1001 , 857 , 1 ] , in which 1000 and 1001 are larger than 857 I 'm g...
function largestOfFour ( arr ) { var largest = [ ] ; for ( var i = 0 ; i < arr.length ; i++ ) { largest.push ( arr [ i ] .sort ( ) .pop ( ) ) ; } console.log ( largest ) ; return largest ; } largestOfFour ( [ [ 4 , 5 , 1 , 3 ] , [ 13 , 27 , 18 , 26 ] , [ 32 , 35 , 37 , 39 ] , [ 1000 , 1001 , 857 , 1 ] ] ) ; Array [ 5 ,...
Why is 857 larger than 1000 and 1001 ? Javascript
JS
I 'm looking for an approach to splitting a four sided shape into a grid . For example : Ultimately I need to be able to convert the resulting shapes to SVG , but I 'm happy to handle conversion to/from another library or coordinate system . What I 'm looking for is how to approach the calculation.Assume the shape is a...
< svg version= '' 1.1 '' xmlns= '' http : //www.w3.org/2000/svg '' xmlns : xlink= '' http : //www.w3.org/1999/xlink '' x= '' 0px '' y= '' 0px '' viewBox= '' 0 0 406.4 233.4 '' xml : space= '' preserve '' > < path class= '' st0 '' d= '' M394.3,232.7c-106-37.8-353.7,0-353.7,0s-90.4-151.2,0-207.3s353.7,0,353.7,0S420.3,154...
Subdivision of Four-Sided , 2D Shape
JS
In this introductory course of Reduxhttps : //egghead.io/lessons/javascript-redux-store-methods-getstate-dispatch-and-subscribe ? series=getting-started-with-redux , the presenter says that the following two lines are identical I 've just searched for ES6 const documentation , and it does not quite answer my question ,...
const { createStore } = Redux ; var createStore = Redux.createStore ;
beginner 's : const definition in Redux confusing
JS
Why do n't getElementsByName , getElementsByTagName , and getElementsByClassName return an HTMLCollection ( W3C , MDN ) instead of a NodeList ( W3C , MDN ) ? All three return a live NodeList of only elements : NodeLists are great , but HTMLCollections are more specific as they can only contain HTML elements . It seems ...
document.getElementsByName ( 'nameAttrVal ' ) ; document.getElementsByTagName ( 'div ' ) ; document.getElementsByClassName ( 'space separated classes ' ) ; document.imageselement.children
Why do n't document.getElementsBy__ methods return an HTMLCollection ?
JS
I have a SVG I am trying to animate with animejs.Basically its a selection path drawing . I managed to animate but the result is wrong.I want this :
var lineDrawing = anime ( { targets : 'path ' , strokeDashoffset : [ anime.setDashoffset , 0 ] , easing : 'easeInOutCubic ' , duration : 4000 , begin : function ( anim ) { document.querySelector ( 'path ' ) .setAttribute ( `` stroke '' , `` # 4a56f2 '' ) ; document.querySelector ( 'path ' ) .setAttribute ( `` fill '' ,...
How to animate my SVG path
JS
GoalI am trying to mimic a List Control Component in React and Redux based on the Google Material Design layout.The list control will allow you to create , rename and delete items in the list without navigating to a new page.The actions for renaming and deleting a list item will be shown in a popup menu component trigg...
class ListItemPage extends Component { constructor ( props , context ) { super ( props , context ) ; } onMenuClick ( ) { } onRename ( ) { } onDelete ( ) { } render ( ) { const { listItems } = this.props ; return ( < div > < ul > { listItems.map ( listItem = > < li > < a href= { ` /items/ $ { listItem.id } ` } > { listI...
Using React how do I toggle the visibility of a nested component from a container component ?
JS
Why does the following return false ?
Object.prototype instanceof Object
Why is Object.prototype instanceof Object false ?
JS
Is it possible to have user code executed between a promise resolution and a promise await return ? Does the specification enforces that Promise callbacks are called immediatly ? I wonder if an event could be handled by the virtual machine between the 2 points , possibly causing side-effects .
function a ( ) { return new Promise ( resolve = > { setTimeout ( ( ) = > { // Between here ... resolve ( ) } , 1000 ) ) } } async function b ( ) { await a ( ) // ... and here ? }
JavaScript ES6 - Possible race condition between promise resolution and event ?
JS
Not quite grasping what 's going on here . Given the array ( arr ) : And the object ( obj ) : Why would arr.indexOf ( obj ) return -1 ( especially since I retrieved the object from the array using it 's 'id ' parameter earlier in the function ) ?
[ { `` first_name '' : `` Dan '' , `` last_name '' : `` Woodson '' , `` id '' : 1 } , { `` first_name '' : `` Jen '' , `` last_name '' : `` Woodson '' , `` id '' : 2 } , { `` first_name '' : `` Yoshi '' , `` last_name '' : `` Woodson '' , `` id '' : 3 } ] { `` first_name '' : `` Yoshi '' , `` last_name '' : `` Woodson ...
Javascript oddness with array of objects and indexOf
JS
I have encountered a very strange bug in Firefox.I have a javascript function in an external file that works perfectly on regular complexity websites . However I have been putting together a few demonstration examples and come across something odd.With html formatted like this ( in an editor ) : The Javascript works as...
< div > < p > Q : Where 's the rabbit ? < /p > < p class= '' faq_answer '' > A : I do n't know , honest < /p > < /div > < div > < p > Q : Where 's the rabbit ? < /p > < p class= '' faq_answer '' > A : I do n't know , honest < /p > < /div > elementsList [ i ] .parentNode.firstChild.appendChild ( finalRender.cloneNode ( ...
Very strange error caused by html whitespace
JS
I have a Bootstrap Carousel with a lot of social embeds from Facebook all containing videos.I wo n't go into specifics of the Bootstrap Carousel as the problem is already visible on this simple jsfiddle and is due to Facebook embed.If you load this page : https : //jsfiddle.net/1L95vqn4/ , and look on Chrome Dev tools ...
$ .ajax ( { url : 'https : //www.facebook.com/plugins/post/oembed.json/ ? url=https : //www.facebook.com/cocacola/posts/1526674334016658 ' , dataType : 'jsonp ' , cache : false , success : function ( data ) { try { var embed_html = ( data.html ) ; $ ( 'div # item1 ' ) .html ( embed_html ) ; } catch ( err ) { console.lo...
Prevent huge amount of xhr/ajax calls on Facebook embed iframe
JS
Reading underscore 's source , I noticed the use of void 0 instead of undefined . I know in some browsers undefined can be overwritten , and that a solution to this , in many cases , is just omitting an argument when calling a function , or return ; -ing . In fact , for minification purposes , it makes much more sense ...
( function ( window , undefined ) { /* ... */ } ( window ) ) ;
var undefined = void 0 ; vs jquery 's closure vs ... ?
JS
I 'm fetching some data with $ .getJSON that I want to asynchronously bind to controller context . I 've come up with this in my route - which works , but I 'm not happy with it : Then , in my template , I can , for example , use : And it works just fine . Is there a better way to write this ( perhaps without promise c...
setupController : function ( controller , model ) { this._super ( controller , model ) ; Em.RSVP.Promise.cast ( Em. $ .getJSON ( ( this.get ( 'ENV.apiBaseURL ' ) ) + `` /users/current/live_matchday_stats '' ) ) .then ( ( function ( _this ) { return function ( s ) { return _this.controller.set ( 'matchdayStats ' , Em.Ob...
Ember.js : Proper way to cast Em. $ .getJSON into a promise and bind response to controller context ?
JS
I 'm serving an embeddable < script > that users can copy/paste into their websites and have content displayed.The script loads a stylesheet and renders some HTML that is injected into the host page.I 'm facing problems displaying special characters ( ü , ö , ä , you name it ) when the host pages are encoded in encodin...
var content = template.render ( model ) ; $ ( ' # some-el ' ) .html ( content ) ; .some-class : :after { content : 'Ümläüts äré fün ' ; }
What 's a working strategy to serve umlauts generated by JS and CSS to all possible host page encodings
JS
How to merge JSON objects using plain ( without jQuery ) JavaScript ? Requirement is to : Convert from : Convert To :
chartData= [ { `` date '' : '' 2014-05-1 '' , '' CAT1 '' :0.1 } , { `` date '' : '' 2014-05-1 '' , '' CAT2 '' :0.2 } , { `` date '' : '' 2014-05-1 '' , '' CAT3 '' :0.3 } , { `` date '' : '' 2014-05-1 '' , '' UNSET '' :0.4 } , { `` date '' : '' 2014-05-2 '' , '' CAT1 '' :0.4 } , { `` date '' : '' 2014-05-2 '' , '' CAT2 ...
How to merge JSON objects using JavaScript ?
JS
Imagine I have the following code : This immediately outputs the results . Now , how do I put a timed delay between each message as a way of back-pressure ( note that I do n't want a buffer ; instead , I want a and b to become Cold Observables ) , like : And have the exact same answer : Alternative : If backpressure ( ...
let a = Rx.Observable.of ( 1 , 2 , 3 ) let b = Observable.zip ( a , a , ( a , b ) = > a + b ) b.forEach ( t = > console.log ( t ) ) b.takeEvery ( 1000 ) .forEach ( t = > console.log ( t ) ) < wait 1s > 2 < wait 1s > 4 < wait 1s > 6
How can I apply timed back pressure in RxJS5 ?
JS
I tried to recursion those arrays to find odd/even numbers then push them to newArr but the result , not an array , that result is the string with numbers the result after found the odd/even numbers.this is the code i wrote , if i do n't write return result + odd ( nums.slice ( 1 ) ) ; the result nothing / undefined , ...
function odd ( nums ) { var result = [ ] ; if ( nums.length === 0 ) { return result ; } else if ( nums [ 0 ] % 2 === 0 ) { result.push ( nums [ 0 ] ) // return odd ( nums.slice ( 1 ) ) } ; return result + odd ( nums.slice ( 1 ) ) ; } ; var arr = [ 1,8,3,4,4,5,9,13,13,9,10 ] ; var print = odd ( arr ) ; console.log ( pri...
recursion in array to find odd numbers and push to new variable
JS
This is kind of a doozy . This issue is most likely server related and so my first recourse was AskUbuntu over here.I 'm trying to have crontab or rc.local or init.d to start a forever script on boot . It attaches a server to a port I can ping with some information and have it run a headless browser for me.That said , ...
var CASPER_PATH = '/home/ubuntu/dev/casperjs/bin/casperjs ' ; // actual binary location , not a symlinkvar SCRIPTS_PATH = '/home/custom_user/endpoints/server.js ' ; var fileName = req.body.source + ' _ ' + req.body.type + '.coffee ' ; // looks like : mysource_my_scrape_type.coffeevar scrapeId = 'test_scrape ' ; var use...
Node 's spawn ( ) silently failing when called from a forever script scheduled on boot
JS
This tutorial by Dan Abramov suggests that the advantage to using selectors that act on global state ( rather than a slice of state ) is that they allow containers to be decoupled from knowledge of the state structure.If that 's the case , should n't we also avoid directly mapping state values to props , and use select...
const mapStateToProps = ( state ) = > ( { isModalVisible : state.modal.isVisible , } ) ; const mapStateToProps = ( state ) = > ( { isModalVisible : isModalVisible ( state ) , } ) ;
React / Redux : Should containers have any knowledge of state structure ?
JS
SetupTwo WSGI servers running locally on different ports . One server returns an html page containing javascript that does a cross-origin ajax request to the other WSGI server using jQuery.origin_server.py Serves the html at http : //localhost:9010.cors_server.py Serves the cross-origin resource that the javascript wil...
# ! /usr/bin/env pythonfrom wsgiref.simple_server import make_serverdef origin_html ( environ , start_response ) : status = '200 OK ' response_headers = [ ( 'Content-Type ' , 'text/html ' ) ] start_response ( status , response_headers ) f = open ( './index.html ' , 'rb ' ) return [ f.read ( ) ] httpd = make_server ( 'l...
Excessive Latency on CORS AJAX Request to Local WSGI Server in Chrome
JS
I was messing around with transitions and I noticed some stuttering and flickering when the transitions are applied to the selection in a different function . If , however , the transition is applied with method chaining , it works exactly as prescribed . Below is small example ( Fiddle ) of simply moving some text . T...
var svg = d3.select ( 'svg ' ) ; var textElem = svg.append ( 'text ' ) .data ( [ 'hello world ' ] ) .attr ( ' x ' , 30 ) .attr ( ' y ' , 100 ) .attr ( 'fill ' , ' # 000 ' ) .attr ( 'id ' , ' a ' ) .text ( function ( d ) { return d ; } ) ; var textElem2 = svg.append ( 'text ' ) .data ( [ 'some text ' ] ) .attr ( ' x ' ,...
Why do transitions flicker/stutter when applied in a separate function ( D3 )
JS
I have URLs in JSON feed n each URL contains one image . I want to validate those URLs which have image or not ( NULL ) . How to validate this using javascript . since I 'm a beginner , i do n't know , how to validate this . thanks
JSON feed with image n NULL { previewImage : '' http : //123.201.137.238:6060/feed/videoplay/Jackie.png '' , } , { previewImage : '' http : //www.snovabits.net/feed/ImageMI/WarCraft.jpg '' , } ,
How to validate a content in URL ( Javascript )
JS
I 'm developing an iOS app and now I 'm stuck with Firebase deploy functions . I 'm trying to send push notifications and I prepared the codes like below.Database structure : And this is the error message.Also in the log , I get errors like : Is the error occurring because I 'm not fetching fcmToken right ? I 've never...
const functions = require ( 'firebase-functions ' ) ; const admin = require ( 'firebase-admin ' ) ; admin.initializeApp ( functions.config ( ) .firebase ) ; exports.pushNotifications = functions.database.ref ( '/messages/ { messageId } ' ) .onCreate ( event = > { const data = event.data ; const fromId = data.fromId ; c...
Error with Firebase deploy function to send push notifications
JS
I am using Patrick Springstubbe multiselect pluging and it works fine . But now I would like to use it for single select . I know I need to set the select to mulitple for the plugin to work . But is there a way to limit the number of option to 1.I have tried This gives the desired effect when you select an option but t...
$ ( `` # ProductCategory '' ) .change ( function ( ) { $ ( `` .ms-options '' ) .css ( `` visibility '' , '' hidden '' ) ; }
How to use PATRICK SPRINGSTUBBE jQuery multiselect plugin for single select
JS
I have a video tag in which I pass video data i.e src and vtt dynamically , I want to keep vtt for the current video only , and remove all other textTracks.Right Now on switching the video , all vtt related to previously played videos start playing inside the video tag.vtt is subtitle
function addVttInvideo ( data ) { // http : //www.html5rocks.com/en/tutorials/track/basics/ // https : //www.iandevlin.com/blog/2015/02/javascript/dynamically-adding-text-tracks-to-html5-video var video = document.getElementById ( 'videoSrc ' ) ; var track = video.addTextTrack ( 'subtitles ' , 'English ' , 'en ' ) ; tr...
Remove all other 'vtt cues ' from video tag
JS
In his Eloquent Javascript , Haverbeke claims that ( page 16 ) : '' In a JavaScript system , most of this data is neatly separated into things called values . Every value has a type , which determines the kind of role it can play . There are six basic types of values : numbers , strings , Booleans , objects , functions...
> typeof function ( ) { } ; 'function ' > typeof { } ; 'object '
Are functions objects or types in Javascript ?
JS
Is there a c # library that can help to write and indent Javascript code.It 's because I 'm writing some c # code that generated some Javascript code . Something like this : And I find that generated a lot of ugly code.So , I thought that maybe a existing library can help me doing that ?
js += `` < script type=\ '' text/javascript\ '' > \n '' ; js += `` function ( ) ... \n '' ;
Library to write javascript code
JS
I 'm curious to know whyreturns true butreturns falseIs the inclusion of the greater than operator coercing the values differently ?
null == undefined null > = undefined
null and undefined inconsistent comparison
JS
this is my first post , but i 'm excited to join this community . I have a question regarding JavaScript which I am completely stumped about . I 'm writing a JavaScript application which pulls data from a server using ajax and adds it to a chart . I 'm using Jquery and Highcharts as the framework and then writing my ow...
function getData ( series , min , max , numpts ) { if ( series === undefined ) { console.log ( `` error on getData '' ) ; return ; } var request = { } ; request.series = series ; if ( min ! == undefined ) { request.start = min ; } //in seconds if ( max ! == undefined ) { request.end = max ; } if ( numpts ! == undefined...
JavaScript method begins w/ variables assigned ? ? very confused
JS
i have started with react native project , earlier was in native code.i wanted to add Amazon Lex so followed below steps from linkhttps : //aws-amplify.github.io/docs/js/interactionsbelow is my App.js filei have just set up amplify library and added interaction for LEX , but started getting below error as i try to run ...
import React from 'react ' ; import { StyleSheet , Text , View } from 'react-native ' ; export default function App ( ) { return ( < View style= { styles.container } > < Text > Open up App.js to start working on your app ! < /Text > < /View > ) ; } const styles = StyleSheet.create ( { container : { flex : 1 , backgroun...
Haste module naming collision : react native app with AWS Service ( Amplify Project )
JS
I try to implement the continuation monad in Javascript to handle continuation passing style and asynchronous control flows . Here is my continuation monad for learning : Apart from cont.ap , whose benefit does n't reveal itself to me , everything works fine.Now I 'd like to mimic the throw/catch mechanism of synchrono...
// auxiliary functionsconst log = prefix = > x = > console.log ( prefix , x ) ; const addk = x = > y = > k = > setTimeout ( ( x , y ) = > k ( x + y ) , 0 , x , y ) ; const inck = x = > k = > setTimeout ( x = > k ( x + 1 ) , 0 , x ) ; const sqr = x = > x * x ; // continuation monadconst cont = { of : x = > k = > k ( x )...
How to apply callcc so that it provides an escape continuation mechanism for use with the continuation monad
JS
I created a Wordpress theme and now I am working on an editor-stylesheet for the block editor to better reflect the look of the theme in the editor . For this , I need to be able to address different post types in there.For the frontend , there is the body_class ( ) function to be used in templates , which inserts - am...
wp.domReady ( function ( ) { var postType = jQuery ( 'form.metabox-base-form input # post_type ' ) .attr ( 'value ' ) ; if ( postType == 'post ' ) { alert ( `` It 's a post ! `` ) ; //in real life some other action ... } } ) ; jQuery ( document ) .ready ( function ( ) { if ( jQuery ( 'body ' ) .hasClass ( 'post-type-pa...
Wordpress : Is it possible to use post-type as part of a css selector in block editor stylesheet ?
JS
I 'm a JavaScript developer who 's learning Lua . I 'm stuck with a problem of getting a function 's arity in the Lua language.In JavaScript , it 's simple : How is it possible to do it this easily in Lua ?
function test ( a , b ) { } console.log ( test.length ) // 2 function test ( a , b ) endprint ( # test ) -- gives an error..
Get arity of a function
JS
Given an array or object with n keys , I need to find all combinations with length x . Given X is variable . binomial_coefficient ( n , x ) .Currently I 'm using this : The output is : So if I want the binomial coefficient x=3 from n=4 I select all the strings with length equal to three . { abc , abd , acd , bcd } .So ...
function combine ( items ) { var result = [ ] ; var f = function ( prefix , items ) { for ( var i = 0 ; i < items.length ; i++ ) { result.push ( prefix + items [ i ] ) ; f ( prefix + items [ i ] , items.slice ( i + 1 ) ) ; } } f ( `` , items ) ; return result ; } var combinations = combine ( [ `` a '' , `` b '' , `` c ...
Efficient algorithm to get the combinations of all items in object
JS
Project I 'm working on uses jQuery.I have a series of Ajax calls being made that load ( ) other HTML fragments which in turn load ( ) other fragments . The whole thing is confusing . I did n't write the code . Is there any tool which will allow me to walk the callstack so I can figure what is calling a method ? any br...
$ .ajaxSetup ( { async : false } ) ;
Complex JavaScript . What called me ?
JS
Our application has a list of tasks , which can grow quite large . The main tasks list has a sidebar , and when a task is selected , it can be edited in the sidebar - which uses a different controller ( TasksSidebarCtrl rather than TasksCtrl that displays the list ) . The selected task is copied , and then merged back ...
< md-list-item my-task-directive ng-repeat= '' task in TasksCtrl.tasks track by task.id '' > TasksService.index ( ) .then ( function ( tasks ) { vm.tasks = tasks.data ? tasks.data : [ ] ; } ) ; $ scope. $ on ( 'task-updated ' , function ( ) { var newTask = TasksService.getUpdatedTask ( ) ; $ timeout ( function ( ) { vm...
Force splice of ng-repeat array whilst using track by
JS
Is it safe to assume that the last script element* in the document when the script runs** is the currently running script ? For example , I want to create a script that can be dropped anywhere in the body of of a page and display an element in the same place . I 'm doing something like this : Assuming the script is in ...
function getCurrentScriptElement ( ) { var scripts = document.getElementsByTagName ( 'script ' ) ; return scripts [ scripts.length - 1 ] ; } var script = getCurrentScriptElement ( ) ; var view = document.createElement ( 'span ' ) ; /* Put stuff in our view ... */script.parentNode.insertBefore ( view , script ) ;
Is it the last ` script ` element the currently running script ?
JS
I was trying to extract strings with using an enum such as : and then later wanted to have a cost scale for the ingredientsbut i wanted to extract coffee to use the string : INGREDIENT.COFFEE like so : but it was showing an error that . is incorrect.I was resorting to : Is there something i am doing , preventing me fro...
var INGREDIENT = { COFFEE : `` coffee '' } var COST = { coffee : 1 } var COST = { INGREDIENT.COFFEE : 1 } ; //target var COST= { } ; COST [ INGREDIENT.COFFEE ] = 1 ;
Writing the Key of JSON with an enum
JS
I want to push functions with params to an array without getting them executed . Here is what i have tried so far : But in this way functions gets executed while pushing . This Question provides similar example but without params . How can I include params in this example ?
var load_helpers = require ( '../helpers/agentHelper/loadFunctions.js ' ) ; var load_functions = [ ] ; load_functions.push ( load_helpers.loadAgentListings ( callback , agent_ids ) ) ; load_functions.push ( load_helpers.loadAgentCount ( callback , agent_data ) ) ;
Add Functions with params to Array Javascript ( Node.js )
JS
I quite often have to bind ? some function that requires arguments . The solution I use is wrapping the function to bind inside an anonymous function.Is there a more elegant way of doing this ?
function foo ( arg_0 ) { // do stuff with : arg_0 } function bar ( ) { var abc ; // stuff happens abc = 'some value ' ; attachEventHandler ( elementId , 'click ' , function ( ) { foo ( abc ) ; } ) ; } bar ( ) ;
Javascript prevent anonymous function ?
JS
So I have an API that will be deployed in a docker container . This API has the authentications controller , simple and not something special.When I start up the API in development mode on my local machine , the auth controller will be found and everything is working fine . Same for building and running it on my local ...
import { Controller , Post , Delete , UseGuards , Request , Body , } from ' @ nestjs/common ' ; import { AuthenticationsService } from './authentications.service ' ; import { JwtAuthGuard } from '../shared/guards/jwtAuth.guard ' ; import { SignInDTO } from './dtos/addGraphNodeToGraphByGraphId.dto ' ; @ Controller ( 'au...
NestJS controller not mapped
JS
I 'm currently studying javascript by following the `` you dont know js '' series . In section `` this & object prototype '' , the author came up with an way to soft bind this . However , I am extremely confused by the code . So I was wondering if someone could kindly explain it to me , steps by steps , what the code r...
//step 1 : if `` softBind '' property does not exist on ` Function.prototye ` if ( ! Function.prototype.softBind ) { //step 2 : create a property named `` softBind '' on `` Function.prototype '' and assign to `` softBind '' the following function Function.prototype.softBind = function ( obj ) { //step 3 : what is the p...
confusion over how `` softBind '' function works
JS
I am using jquery 1.10 . I want to know what the difference is between these three functions.Which function is better and why ? What is the purpose of the delegate function ? Can anybody explain me ?
$ ( `` .dropdown-menu '' ) .on ( `` click '' , `` .show_opt_menu '' , function ( ) { alert ( `` hello '' ) ; } ) ; $ ( `` .dropdown-menu .show_opt_menu '' ) .on ( `` click '' , function ( ) { alert ( `` hello '' ) ; } ) ; $ ( `` .dropdown-menu '' ) .delegate ( `` .show_opt_menu '' , `` click '' , function ( ) { alert (...
What is the difference between jquery on with / without selector parameter and jquery delegate ?
JS
What 's happening here and why ?
document.write ( 0154 ) ; // === 108
Why does 0154 === 108 ?
JS
I 've been tasked with rewriting this terrible piece of code which is meant to sequentially fade in layers on a map ( they are all transparent pngs ) on a web page . It needs to operate in a sequence , then loop back to the start where no layers are visible , and fade back in one at a time . This sequence should repeat...
setInterval ( function ( ) { $ ( `` # layer-1 '' ) .fadeIn ( 1000 , function ( ) { $ ( `` # layer-2 '' ) .fadeIn ( 1000 , function ( ) { $ ( `` # layer-3 '' ) .fadeIn ( 1000 , function ( ) { $ ( `` # layer-4 '' ) .fadeIn ( 1000 , function ( ) { $ ( `` # layer-5 '' ) .fadeIn ( 1000 , function ( ) { $ ( `` # layer-6 '' )...
How to reduce nested callbacks in javascript/jquery
JS
I am injecting javascript into a PHP website to avoid a pop-up , to submit a form automatically . Also , there is an issue with jquery so I am using plain javascript.This is the form on the page : This is my javascript : When I manually click on the form , I know that these values are setBut when my javascript submits ...
< form action='http : //mywebsite.com/index.php ? & act=MYFUNCTION & CODE=01 & CookieDate=1 ' name='subscribe_check ' method='POST ' > < input type='hidden ' name='value1 ' value='dynamicallygenerated ' > < input type='hidden ' name='Value2 ' value='BlogSection ' > < input type='hidden ' name='Value3 ' value='BlogName ...
Php differentiating between javascript and user click ?
JS
I am loading some JS from an external source right before my < /body > tag . I am experimenting to see what happens if the server hangs while trying to serve this third party JS . It seems that everything on my page works just fine , but the browser still spins as though the page is still loading . Is there a way to lo...
< script > var resource = document.createElement ( 'script ' ) ; resource.src = `` https : //myserver.com/js/myjs.js ” ; var script = document.getElementsByTagName ( 'script ' ) [ 0 ] ; script.parentNode.insertBefore ( resource , script ) ; < /script > < script async src= '' https : //myserver.com/js/myjs.js '' > < /sc...
JS loaded asynchronously in body keeps browser in `` loading '' mode
JS
I need to have a sort on two strings take the > and < symbols into consideration . So , for example , the sort might look likeSo basically all the strings with < are first , followed by a normal sort , followed by all numbers with a > symbol . I 'd also like the sort to respect the exact order shown ( e.g . > 100 appea...
< 20 < 40 < 1000.1101,000,000.75 > 100 > 1,000 if ( $ this.hasClass ( 'sort-mixed ' ) ) { sort_func = sort_mixed ; } $ rows.sort ( sort_func ) ; function sort_mixed ( a , b ) { var val_a = $ ( a ) .children ( ) .eq ( column_index ) .text ( ) ; var val_b = $ ( b ) .children ( ) .eq ( column_index ) .text ( ) ; val_a = N...
How do I sort taking greater than and less than into consideration ?
JS
i have a node.js server that i want to be able to handle exceptions without crashing , and i 've got code kinda like the below . What i 'm wanting to know , with all the event-driven awesomeness and callbacks and lambdas and all that , will my exceptions still be caught by my main entry point ? Thanks
try { http.get ( ... , function ( results ) { // Might get an exception here results.on ( 'data ' , function ( ) { // Might also get an exception here } ) ; results.on ( 'end ' , function ( ) { // Might also get an exception here } ) ; } ) ; } catch ( e ) { // Will the exceptions from the lambdas be caught here ? conso...
Do exceptions get caught in lambdas in javascript / node.js ?
JS
I have arrays of arrays which contains something like this : I 've tried .map ( ) and Object.assign but I dont know how to implement it . I want this as an output : What should I use ? This is what Im came up so far :
var values = [ [ 1 , 2 , 3 ] , [ 3 , 2 , 1 ] ] values = [ { 'up ' : 1 , 'middle ' : 2 , 'down ' : 3 } , { 'up ' : 3 , 'middle ' : 2 , 'down ' : 1 } ] const object1 = [ [ 1,2,3 ] , [ 3,2,1 ] ] , object = [ ] object1.forEach ( function ( array ) { object.map ( value = > ( { 'up ' : array [ 0 ] , 'mid ' : array [ 1 ] , 'd...
Convert arrays of arrays to object with key
JS
In directive bind method , there is a vnode.context. $ watchand every time that directive added to HTML , it is also adding another watcher with previous watcher . Because of that same watchers are calling more than once . Is there any way to destroy the previous watcher when directive unbind method called .
Vue.directive ( `` dynamic-lookup '' , { bind : function ( el , binding , vnode ) { let dependency = setValue ( `` dynamic-lookup-dependency '' ) ; if ( dependency ) { vnode.context. $ watch ( dependency , function ( newVal , oldVal ) { } ) ; } ) ; } } , unbind : function ( el , binding , vnode ) { console.log ( `` unb...
destroy watch in vnode context in vuejs2
JS
My scenario is : On clicking a button , import datas on a html into a PDF file.Since this PDF must have some complicated required style , so my first step is to transfer this page into a image using html2canvas.js and then import this image to a PDF with jsPDF.js And when the data is too large the PDF must be split to ...
function initTemplate ( ) { datas=getData ( ) ; var templateData=_.template ( $ ( ' # tpl ' ) .html ( ) , datas ) ; $ ( ' # tplW ' ) .html ( templateData ) ; getPDF ( ) ; // $ ( ' # tplW ' ) .append ( _.template ( $ ( ' # tpl ' ) .html ( ) , datas ) ) ; // $ ( 'body ' ) .html ( _.template ( $ ( ' # tpl ' ) .html ( ) , ...
Import long html into split PDF
JS
I 've got several divs on my page that look like this : When the user hovers over them and scrolls with the scroll wheel they scroll fine . The trouble is that , when the user reaches the bottom , the page itself starts scrolling instead . Is there a way to stop this happening ( using javascript if necessary ) , so tha...
< div style= '' height:200px ; overflow : auto ; '' > < div style= '' height:300px ; '' > < ! -- Lots of text here -- > < /div > < /div >
How can I prevent the page scrolling when I have scrolled to the bottom of a div inside it ?
JS
If I open JS console and write : and after : console show me ( rightly ) Now ... sometimes I need to inject my code inside an existing script and I do n't have tool to determinate if a let variable is already defined.I try with this code , but there is evident problem with JS scope and logic ... . ( comment the code ) ...
let foo ; let foo = `` bar '' Uncaught SyntaxError : Identifier 'foo ' has already been declared let foo ; // Gloabl variable empty declare in a code far , far away console.log ( foo ) ; // undefinedconsole.log ( typeof foo === `` undefined '' ) ; // test that determinate if condition is trueif ( typeof foo === `` unde...
JS : How to prevent let double declaration ? / determine if let variable is defined
JS
I have code something like the above . I need to add a class for the ul tag generated after the Accounts label . Something like the following does n't work : My purpose is to have a mega menu for the navigation . To add functionality to it I need to have classes within the generated menu code .
< configdata > < home > < label > Home < /label > < controller > dashboard < /controller > < action > index < /action > < /home > < accounts > < label > Accounts < /label > < controller > accounts < /controller > < action > index < /action > < pages > < sales > < label > Sales Accounts < /label > < controller > sale < ...
Zend navigation with XML file
JS
I 'm trying to follow the ReactJS tutorial at https : //reactjs.org/tutorial/tutorial.html . I 'm using Emacs to edit index.js , and when I edit the file ( add a newline , let ` s say ) , even without saving the file , instantly the server crashes and I get this output : I 've checked for the file . # index.js and it '...
/home/myname/Code/project/reactapp/node_modules/react-scripts/scripts/start.js:19 throw err ; ^ [ Error : ENOENT : no such file or directory , stat '/home/myname/Code/project/reactapp/src/. # index.js ' ] { errno : -2 , code : 'ENOENT ' , syscall : 'stat ' , path : '/home/myname/Code/project/reactapp/src/. # index.js '...
ReactJS local server crashes after editing file in Emacs even without saving
JS
The above code was run in Google Chrome Version 62.0.3202.94 ( Official Build ) ( 64-bit ) on macOS Sierra Version 10.12.6.As you can see , the behaviour does not depend on whether or not you specify the radix.Note : I usually use ~~ instead of using parseInt , it looks safer.Why am I getting these results ?
console.log ( parseInt ( 0.0000008 ) ) // > 8console.log ( parseInt ( 0.000008 ) ) // > 0console.log ( parseInt ( 0.0000008 , 10 ) ) // > 8console.log ( parseInt ( 0.000008 , 10 ) ) // > 0
Strange and inconsistent behaviour of parseInt on decimal fractions
JS
I apologize in advanced if this question is too broad . In fact it 's 4 different questions , but all related to the same piece of code , and I think they all revolve around the same principle.I decided today , after using JS for years , to actually start learning how JS works instead of treating it like C that runs in...
var myDOM = ( function ( ) { // # 1 var myDOM = function ( elems ) { // # 2 return new MyDOMConstruct ( elems ) ; } , MyDOMConstruct = function ( elems ) { this.collection = elems [ 1 ] ? Array.prototype.slice.call ( elems ) : [ elems ] ; return this ; // # 3 } ; myDOM.fn = MyDOMConstruct.prototype = { forEach : functi...
Javascript : What Does This Code Do ?
JS
I was plundering some recent react repos this weekend and I came across an example using ES6 class syntax for component composition that went a little something like this.notice the : :this.submit in lieu of this.submit.bind ( this ) it works , and I can not find documentation anywhere on this feature , I feel like a c...
class MyThing extends Component { constructor ( props ) { super ( props ) this.state = { something : 'the thing ' } } submit ( ) { // do stuff } render ( ) { < div > < button onClick= { : :this.submit } > Fire Submit < /button > < /div > } }
Mysterious syntax onClick= { : :this.submit }
JS
i 'm trying to learn how to work with angular firmly and i 'm having trouble understanding some of the syntax used in the guides and examples on the official website.when defining a button form control i saw this template : my question is : what is the meaning of `` : : '' before the `` to.type '' and `` to.btnType '' ...
< div > < button type= '' { { : :to.type } } '' class= '' btn btn- { { : :to.btnType } } '' ng-click= '' onClick ( $ event ) '' > { { to.text } } < /button > < /div > < a ng-class= '' { 'btn-primary ' : to.isPrimary , active : to.isActive } '' class= '' btn , btn-default '' / >
meaning of : : in angular formly
JS
My markup is set up like so : I have 2 buttons using jquery to show and hide ( which act as a show more show less ) the two tags within my h5 tag . However I ca n't seem to use this code to ensure that the strong tag with id= '' head2 '' is not displaying . I 've tried I 've also triedIm unsure if this has anything to ...
< div class= '' media-body '' > < h5 class= '' media-heading '' > < strong id= '' head '' > { { $ blog- > Title } } < /strong > < strong id= '' head2 '' > { { $ blog- > Title } } < /strong > < /h5 > < button id= '' hide '' > Hide < /button > < button id= '' show '' > Show < /button > < /div > < style > .head2display : ...
How to display : none between parent and sibling tags when using show more show less Jquery
JS
The issue seems to be that certain letters like g , y , q , etc . that have a tail that slopes downwards , do not allow for vertical centering . Here 's an image to showcase the problem .The characters in the green box are basically perfect , as they have no downward tail . Those in the red box demonstrate the problem....
.avatar { border-radius : 50 % ; display : inline-block ; text-align : center ; width : 125px ; height : 125px ; font-size : 60px ; background-color : rgb ( 81 , 75 , 93 ) ; font-family : `` Segoe UI '' ; margin-bottom : 10px ; } .character { position : relative ; top : 50 % ; transform : translateY ( -50 % ) ; line-he...
How to vertically align all text in CSS ?
JS
I am using an extension of HashLocation to implement a hashbang url type for Ember.js.Here is the code snippet : I use this by reopening the Router : However , on running the application , i 'm hitting the following deprecation : I ca n't find any information on how to do this . Does anyone have any implementation snip...
( function ( ) { var get = Ember.get , set = Ember.set ; Ember.Location.registerImplementation ( 'hashbang ' , Ember.HashLocation.extend ( { getURL : function ( ) { return get ( this , 'location ' ) .hash.substr ( 2 ) ; } , setURL : function ( path ) { get ( this , 'location ' ) .hash = `` ! `` +path ; set ( this , 'la...
Ember.js deprecation of registerImplementation in favour of App.initializer
JS
I 'd like to output some values from this site . With the browser inspector I located the URL to the JSON that has that information that I want . Once with the JSON , I can extract the values just fine.The issue is that the URL to the JSON only works for a limited amount of time . If I try to access it later ( via brow...
{ `` status '' : 401 , '' response '' : `` unauthorized '' } function getUserAndJSON ( ) { var url = 'https : //asunnot.oikotie.fi/api/cards ? cardType=100 & conditionType % 5B % 5D=1 & conditionType % 5B % 5D=2 & limit=24 & locations= % 5B % 5B1669,4 , % 22Lauttasaari , % 20Helsinki % 22 % 5D , % 5B14714,5 , % 2200340...
How to get around a 401 unauthorized error ?
JS
Can anyone explain why these bullets will change color correctly in Firefox and IE , but not in Chrome ( my current version is 47.0.2526.106 ) ? Why do the bullets in the first ul stay white , but the others change initially ? Note that I get the same behavior whether I bind to class or use the ng-class attribute.Is th...
angular.module ( 'myApp ' , [ ] ) .controller ( 'myCtrl ' , [ ' $ scope ' , ' $ interval ' , function ( $ scope , $ interval ) { var values = [ 'Hello ' , 'Oops ' , 'Uh-Oh ... ' ] ; var classes = [ 'good ' , 'warning ' , 'danger ' ] ; var nItems = 8 ; $ scope.items = [ ] ; for ( var i = 0 ; i < nItems ; i++ ) { $ scope...
Bullet colors do n't display correctly in Chrome when changed by Angular
JS
I have the following code . It 's a JavaScript module.I do n't understand the section : I think it is creating an object referencing 'this ' module and then assigns the Cahootsy variable to a global Cahootsy variable . What I do n't understand is why 'this ' needs to be assigned to Cahootsy.scope
( function ( ) { // Object var Cahootsy ; Cahootsy = { hello : function ( ) { alert ( 'test ' ) ; } , } ; ( Cahootsy.scope = ( function ( ) { return this ; } ) ( ) ) .Cahootsy = Cahootsy ; return Cahootsy ; } ) .call ( this ) ; ( Cahootsy.scope = ( function ( ) { return this ; } ) ( ) ) .Cahootsy = Cahootsy ;
Javascript Modules
JS
I want to avoid data multiplication , so i wanted to create a loop for calling my dataprovider for different site_id 's . I created a while loop and set the state values within this while loop . What I realized that from my 2 element array ( I have 2 sites ) only 1 is being set in the state , but the other one not . On...
class Dashboard extends Component { state = { username : localStorage.getItem ( 'username ' ) , siteid : [ { id : 1 , daily : `` EKdaily '' , weekly : `` EKweekly '' , monthly : `` EKmonthly '' , total : `` EKtotal '' , } , { id : 2 , daily : `` AKdaily '' , weekly : `` AKweekly '' , monthly : `` AKmonthly '' , total :...
React setState does not set state during a while loop
JS
Setting a property descriptor like this : ... should , as far as I know , make the someFunction property of window non-writable . It works for function expressions as I expect , whether the function is directly assigned to the object property ... fiddle ... or assigned to a global variable : fiddleHowever , it does n't...
Object.defineProperty ( window , 'someFunction ' , { value : function ( ) { alert ( 'safe ' ) ; } , writable : false , enumerable : false , configurable : false } ) ; window.someFunction = function ( ) { alert ( 'boom ! ' ) ; } someFunction ( ) ; // safe var someFunction = function ( ) { alert ( 'boom ! ' ) ; } someFun...
Why does a function declaration override non-writable properties of the global object ?
JS
I want to create a javascript library , so I thought making it an immediately self executing function would be a nice thing to do to ensure scope safety and everything.But now I 'm running into a problem with using the `` this '' keyword that I do n't quite understand.How can I make a code like this work correctly ? Cu...
( function ( ) { function lib ( ) { this.image = document.getElementById ( `` image '' ) ; this.parts = [ { name : `` part1 '' , num : `` 1 '' } ] ; this.init = function ( ) { $ ( parts ) .each ( function ( ) { var partNum = this.num ; image.getElementById ( partNum ) .addEventListener ( `` click '' , function ( ) { to...
Immediately self executing function and `` this ''
JS
In Chai , you can do stuff like the following : exist is not a function call , but this still works in testing frameworks . The opposite ( expect ( { } ) .to.not.exist ) causes tests to fail , but again , exist is not a function call.How do these assertions work without making me call a function ? In fact , if I try to...
expect ( { } ) .to.exist ;
How do assertion libraries such as Chai work without forcing a call to a function ?
JS
for example , If value is array , it have to be Array constructor . It 's not an array like object . because array like object just has array property , not like [ ] .How can it be ? add : If you can , show simple example code , please.like
$ ( document ) // [ # document ] : document object in arraytypeof $ ( document ) // `` object '' $ ( document ) .constructor // function Object ( ) { [ native code ] } or function ( a , b ) { return some function ; } a = ... console.log ( a ) // [ ... ] console.log ( a.constructor ) // function Object or something
jQuery 's return value is Array , but constructor is Object . how ?
JS
I recently upgraded to protractor 2.5.1 and all of my tests are now failing . I suspect it is something to do with Jasmine but I 'm not sure how to fix . Any help would be appreciated , thank you in advance.Here is the error I receive : Here is my test , however the browser never even navigates to the baseUrl , it just...
Should login successfullyMessage : ReferenceError : testFn is not definedStack : ReferenceError : testFn is not definedat Object . ( c : \GlobalSeedField\Gsfm_Web\EndToEnd.Tests\node_modules\jasminewd2\index.js:81:16 ) at attemptAsync ( c : \GlobalSeedField\Gsfm_Web\EndToEnd.Tests\node_modules\jasmine-core\lib\jasmine-...
Protractor 2.5.1 ReferenceError : testFn is not defined
JS
When trying to create a login form with outlined text fields in Vutify , the chrome autocomplete overlap with labels , you can regeneare here please fill and submit , then go back .
< v-text-field v-model= '' email '' label= '' e-mail '' name= '' email '' outlined prepend-icon= '' mdi-account '' type= '' text '' required > < /v-text-field >
How fix issue with chrome auto complete overlap with labels in vuetify ?
JS
I just found really interesting behaviour in ie8 . It turns out null is not always null.Anyone has an explanation for that ?
// just normal , casual null hanging out in the sunvar nullA = null ; // query for non existing element , should get null , same behaviour also for getElementByIdvar nullB = document.querySelector ( 'asdfasfdf ' ) ; // they are equalconsole.log ( nullA === nullB ) ; // falsenullA instanceof Object ; // will throw 'Obje...
IE8 querySelector null vs normal null
JS
i 'm developing a phonegap app using a lot of javascript . Now i 'm debugging it using Safari Developer Tool , in particular i 'm focused on some button that on the device seems to be a bit luggy.So I 've added some console.timeEnd ( ) to better understand where the code slow down , but the `` problem '' is that when i...
function scriviNumeroTastiera ( tasto ) { console.time ( 'Funzione ScriviNumeroTastiera ' ) ; contenutoInput = document.getElementById ( 'artInserito ' ) .value ; if ( $ ( ' # cursoreImg ' ) .css ( 'display ' ) == 'none ' ) { // $ ( ' # cursoreImg ' ) .show ( ) ; } else if ( tasto == 'cancella ' ) { //alert ( contenuto...
Javascript run faster if console opened
JS
I am using https : //github.com/glslify/glslify to share code between glsl shaders.I have a vert shader that is trying to include a module at the top the vert has : decodeJointAndPalette is also dependent on the JointAndPalette struct as its return definitionJointAndPalette looks like : decodeJointAndPalette looks like...
# pragma glslify : JointAndPalette = require ( './JointAndPalette.glsl ' ) ; # pragma glslify : decodeJointAndPalette = require ( './decodeJointAndPalette.glsl ' ) ; JointAndPalette jointAndPalette = decodeJointAndPalette ( inputProps ) ; struct JointAndPalette { int jointId ; int paletteId ; } ; # pragma glslify : exp...
glslify how to share a struct between modules
JS
I am basically quite sure this pattern must exist and possess a name ... for now I will call it `` gate pattern '' ... Here it is : In my webpage 's javascript , I have to trigger various asynchronous processes . Let 's not discuss how trully async js is , but anyway I have to trigger 2 or 3 AJAX calls , must be sure ,...
1 : cropStore loaded ( ) 2 : resizeEvent ( ) 3 : productStore loaded ( ) onEvent ( 'load ' , { ... . // whatever has to happen in response to cropStored , resized , etc ... // lastly : f1 = true ; //resp f2 , f3 , ... gatedAction ( ) ; } gatedAction ( ) { // Gate if ( ! f1 ) return ; if ( ! f2 ) return ; if ( ! f3 ) re...
Is there a name for this pattern ?
JS
I have been trying recently to make a slide of divs , using a script named Owl-Carousel , where divs are spaced by 10 px each so dragging looks nice.I made the whole code for showing purpose : http : //codepen.io/anon/pen/VLZmWdI tried modifying the margins without success.The CSS is as follow : How can I space slides ...
.generic { // header on top of slide , must have wrapper width background-color : red ; height : 30px ; text-align : center ; } .item { // item ( slide ) inside the owl carousel , must have wrapper width height : 300px ; background-color : # 7FFFD4 ; //margin-right:10px ; // gives the spacing between slides , but works...
Spacing between superposed divs , without affecting width
JS
In laravel I used to call ajax for my select box ( it is like binary tree , ex : cat1 , cat2 are parent id then cat3 , cat4 , cat5 are childs of parent cat1 , cat6 , cat7 are childs of cat2 and so on.. ) .Onchange function is also working , but showing ajax error Uncaught TypeError : $ .ajax is not a functionThis is my...
< script src= '' https : //ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js '' > < /script > < meta name= '' csrf-token '' content= '' { { csrf_token ( ) } } '' / > < script > var CSRF_TOKEN = $ ( 'meta [ name= '' csrf-token '' ] ' ) .attr ( 'content ' ) ; function fun_end_cat ( cat_id ) { //alert ( `` test '' ...
In laravel blade page saying $ .ajax is not a function
JS
I have an angular directive that I 'm using to place a button form . The template is hidden until the user needs to see it . It 's a simple template that works by itself , but when I combine it into the larger form the template does not appear . Here is the directive : Then the html that works : And the html snippet th...
.directive ( 'buttonToggle ' , function ( ) { return { restrict : ' A ' , scope : { myBtnArr : `` = '' } , template : ' < button ng-click= '' click ( ) '' > { { myBtnTxt [ myBtnArr ] } } < /button > ' , link : function ( scope ) { scope.myBtnTxt = [ `` AND '' , `` OR '' , `` NOT '' ] ; scope.click = function ( ) { scop...
Angular Template Not Showing with ng-hide
JS
Many times , I needed to write such a lazy asynchronous loading in Javascript : Here , myvar would be some attribute of a hash , not a local variable . loadMyVarAsynchronously loads asynchronously the value for myvar ( with , for example , a Promise or a JQuery Deferred ) Is there a pattern to avoid having to write twi...
if ( myvar ! = undefined ) { doSomeTreatment ( myvar ) } else { loadMyVarAsynchronously ( ) .then ( function ( value ) { myvar = value doSomeTreatment ( myvar ) } ) } doSomeTreatment ( myvar )
How to avoid this async lazy pattern ?
JS
Let 's say we have a function that looks like this : This function should return the value of x where x is available in the global scope . Initially this is undefined but if we define x : Then we can expect fn to return 42.Now let 's say we wanted to render fn as a string . In JavaScript we have toString for this purpo...
const fn = ( ) = > x ; const x = 42 ;
Is there a simple method of turning a global var into a local var ?