lang
stringclasses
4 values
desc
stringlengths
2
8.98k
code
stringlengths
7
36.2k
title
stringlengths
12
162
JS
Below is my Javascript file . The snows all appear good at the beginning , but when some of them hit the screen bottom , some kind of weird behavior happens . Snow start to behave unexpectedly and move up and down repeatedly not in a way that is programmed . I could not figure out why by stating at my codes . Can anyon...
/*1. mimic the snow falling*/ $ ( document ) .ready ( function ( ) { // get the height and width of the browser windowvar windowHeight = $ ( window ) .height ( ) ; var windowWidth = $ ( window ) .width ( ) ; // set the height and width of the # snowingScreen div equivalent to that of the window 's $ ( ' # snowingScreen...
Why my snow go backward ? ( a program that mimic snowing )
JS
Easy question for a coder well-versed in JS . I 'm building a Wordpress site that uses jQuery AJAX methods , reloading either my entire content area when a top nav link is clicked or my main content area when a sidebar nav link is clicked . I want to be sure that the AJAX call is only issued if the user 's browser supp...
$ my_arr = get_browser ( null , true ) ; if $ my_arr [ 'javascript ' ] == 1 { echo ' < script type= '' text/javascript '' src= '' path/to/script '' ' ; } < ? php /** * The template for displaying all pages . * $ ajxy = $ _GET [ 'ajxy ' ] ; if ( ! is_null ( $ ajxy ) ) { $ ajax_code = $ ajxy ; } if ( ! $ ajxy ) { get_hea...
Graceful Javascript Degradation - external source files
JS
htmljQueryabove codes is fine and working . you can feel it here.Now , try thisin FF 3.6 , it gives an error on the console An invalid or illegal string was specified '' code : `` 12 elem [ name ] = value ; and the div is still editable.I suspected it was the jQuery selector , but is not . By further inspection , it wa...
< div contentEditable= '' true '' > testing ... . < /div > $ ( document ) .ready ( function ( ) { $ ( ' [ contenteditable ] ' ) .removeAttr ( 'contenteditable ' ) ; } ) ; $ ( ' [ contentEditable ] ' ) .removeAttr ( 'contentEditable ' ) ; // notice the CamelCase of the string contentEditable
is this a bug ? please check it out
JS
Run the following code in any browser ( try it several times ) : In my understanding , the above code would result console output being : But in Firefox ( v38.0.1 ) , it produces the following output : Please explain why Firefox do it this way . Do n't know if it 's a bug or Firefox 's own standard.You can see a live d...
console.log ( 'processing : task # 1 ' ) ; setTimeout ( function ( ) { console.log ( 'processing : task # 3 ' ) ; } ,0 ) ; alert ( 'See console logs ' ) ; console.log ( 'processing : task # 2 ' ) ; `` processing : task # 1 '' '' processing : task # 2 '' '' processing : task # 3 '' `` processing : task # 1 '' '' process...
code executed in wrong order in Firefox with setTimeout after alert
JS
I 've seen a lot of jQuery code like this , needless to say I do n't like it : I realize people are doing this because the above event binding and handling requires the html structure to be available on the page , but it leads to mixing the presentation , logic and configuration all over the views of the web site . Als...
< div id= '' myDiv '' > < a class= '' clickable '' href= '' # '' > Click Me < /a > < a class= '' clickable '' href= '' # '' > Click Me < /a > < a class= '' clickable '' href= '' # '' > Click Me < /a > < a class= '' clickable '' href= '' # '' > Click Me < /a > < /div > < script > $ ( document ) .ready ( function ( ) { $...
jQuery event binding and handling
JS
I have a d3 & Ionic project that can be found on github here . I did n't create a Plunkr , because the bug must be reproduced via the android emulator or android device.I have a graph that pans and zooms . I 'm attempting to keep about 60 data points in the graph at a time . When the user reaches the `` edge '' meaning...
import { Component , ElementRef , OnInit , ViewChild } from ' @ angular/core ' ; import { Content , LoadingController , NavController , PopoverController } from 'ionic-angular ' ; import { UsageLayer } from './usage-layer ' ; import { Observable } from 'rxjs/Rx ' ; import { UsageService } from './usage.service ' ; impo...
d3 zoom with touch devices sometimes behaves weirdly ( using IONIC )
JS
What 's the point of naming function expressions if you ca n't really reference them by the names you give them ?
var f = function g ( ) { console.log ( `` test '' ) ; } ; g ( ) ; // ReferenceError : g is not defined
What 's the point of naming function expressions if you ca n't really reference them by the names you give them ?
JS
What I am trying to do is to write a function to replace a single word in a given sentence . One of the requirements is so that the case of the replaced word will be preserved as with the original.I wrote the following function : Everything works fine , beside the fact that the case of the after word is not the same as...
function replace ( str , before , after ) { var re = new RegExp ( ' ( \\.* ) ? ( ' + before + ' ) ( \\.* ) ? ' , ' i ' ) ; return str.replace ( re , after ) ; } // DEBUGconsole.log ( ' -- -- - DEBUG START -- -- - ' ) ; var tasks = [ replace ( `` A quick brown fox jumped over the lazy dog '' , `` jumped '' , `` leaped '...
Dynamic RegExp with case preservation in JavaScript
JS
I have a data set containing underscore ( _ ) variable name . Such as below : I want to split them into nested object/array , Below is the result I want.How can I write a recursive method to achive it instead of hardcoded ? Maybe it should allow to handle deeper nested object such as `` p_2_one_two_category : 'value ' ...
const data = { m_name : 'my name ' , m_address : 'my address ' , p_1_category : 'cat 1 ' , p_1_name : 'name 1 ' , p_2_category : 'cat 2 ' , p_2_name : 'name 2 ' } { m : { name : `` my name '' , address : `` my address '' } , p : { `` 1 '' : { category : 'cat 1 ' , name : 'name 1 ' } , `` 2 '' : { category : 'cat 2 ' , ...
How to split object into nested object ? ( Recursive way )
JS
It seems unlikely that I found some kind of glaring cross-browser bug . But according to the documentations Reflect.set is supposed to use the 4th parameter as the thisArg ( for example if the set variable is a setter ) . The first argument is the object the value is to be set on , yet whenever I supply any object as t...
var target = new Object ; var thisArg = new Object ; Reflect.set ( target , 'variable ' , 52 , thisArg ) ; target.variable == undefinedthisArg.variable == 52
Reflect.set not working as intended
JS
This is not necessarily an issue , more a curiosity that came up via an ESLint error which led me to wonder if there was a better way that just disabling ESLint for this line . Consider the code snippet below . ESLint will give an error if the react/destructuring-assignment rule is enabled , preferringconst { arrayToPr...
const myArrays = { arrayOne : [ 'one ' ] , arrayTwo : [ 'two ' ] , arrayThree : [ 'three ' ] , } const arrayPrinter = function arrayPrinter ( arrayName ) { const arrayToPrint = myArrays [ arrayName ] return arrayToPrint } console.log ( arrayPrinter ( 'arrayTwo ' ) )
Possible to destructure in JavaScript via bracket notation ?
JS
I have declared a state using $ stateProvider . The state looks like this : In HTML I have a link with href= '' /chat/ : { { user._id } } . In the browser it works fine , but when I run it on an Android device tells me that the link does n't exist . Any ideas ?
.state ( 'tabs.chat1 ' , { url : `` /chat/ : id '' , views : { 'chat1-tab ' : { templateUrl : `` templates/chat1.html '' , controller : `` chatController1 '' } }
Why $ stateProvider does n't work in ionic real device ?
JS
I ran into the following problem . My JavaScript structure is like the following.I created an object that contains all the controllers . Those controllers have their own responsibilities . Below code belongs to the main.js file that is called first : main.jsWithin the function init ( ) I call the controllers ' initiali...
var App = { } ; App.init = function ( ) { console.log ( 'init ' ) ; App.uiController.init ( ) ; App.heroController.init ( ) ; } App.uiController = { root : 0 , init : function ( ) { // Development console.log ( 'init uiController ' ) ; root = this ; // Call functions root.doSomething ( ) ; } , doSomething : function ( ...
How to use controller-scoped version of this to refer to the current controller in JS ?
JS
I create two scenes and two renderers , one is for simple 3D mesh sphere and another is for svg circle . SVG scene sits on top of Mesh scene , like an overlay . Sphere and circle are placed on the same position in 3D space . I use OrbitControls to look around . When program loads I see sphere and the circle in the same...
camera = new THREE.PerspectiveCamera ( 75 , window.innerWidth / window.innerHeight , 1 , 10000 ) ; camera.position.z = -50 ; scene = new THREE.Scene ( ) ; scene.background = new THREE.Color ( 0xff0000 ) ; meshScene = new THREE.Scene ( ) ; meshScene.background = new THREE.Color ( 0x000000 ) ; // 3d sphere mesh added to ...
SVGRenderer with OrbitControls shows two SVG elements on opposite sides
JS
I have the following code ( I am using the jQquery libary ) : My Question : When I do obj.key = jsonobj and I change values in the new obj.key . Why do values in jsonobj then also change ? And how would I avoid that ? ( I want a new `` copy '' of jsonobj ) .I made this test case : http : //jsfiddle.net/WSgVz/
var obj = { } ; var objstring = ' { `` one '' : '' one '' , '' two '' : '' two '' , '' three '' : '' three '' } '// first console outputconsole.log ( objstring ) ; var jsonobj = $ .parseJSON ( objstring ) ; // second console outputconsole.log ( jsonobj ) ; obj.key = jsonobj ; obj.key.test = `` why does this affect json...
Can someone explain me this javascript object `` copy '' behavior
JS
I am working on a Dimple/D3 chart that plots missing days ' data as 0 . I was able to get nrabinowitz 's excellent answer to work , nearly.My data 's timestamp format is YYYY-MM-DD HH-MM , and the hashing + D3.extent time interval in days results in 0-points every day at midnight , even if there is data present from la...
date fruit count2013-12-08 12:12 apples 22013-12-08 12:12 oranges 52013-12-09 16:37 apples 1 < - oranges inserted on 12/09 as 02013-12-10 11:05 apples 62013-12-10 11:05 oranges 22013-12-10 20:21 oranges 1 ... var dateHash = data.reduce ( function ( agg , d ) { agg [ d.date.setHours ( 0,0,0,0 ) ] = true ; return agg ; }...
Separate data from datahash
JS
I have a directive that shows a list of student information on a template and on mouseenter it then shows additional student information . I want to be able to go back to the initial state on mouseleave.Tried all the resources and not much luck.html - this is where i 'm injecting my directivehtml directive templatedire...
< div ng-repeat= '' student in studentPortfolio '' > < portfolio-view student= '' student '' > < /portfolio-view > < /div > < div class= '' outer-box '' > < img src= '' { { student.picture } } '' alt= '' { { student.name.first } } { { student.name.last } } '' style= '' width : 200px ; height : 200px '' > Name : { { stu...
Angular Directive mouseenter/mouseleave working but not setting to initial state after mouseleave
JS
I am confused about the following problem:defined onunhandledrejectionand two test functionswhen i called test1 , only caught one onunhandledrejection , but when i called test2 , i caught two.What is the difference between test1 and test2 ?
window.onunhandledrejection = event = > { event.preventDefault ( ) ; console.log ( 'catch unhandlerejection ' , event ) } function test1 ( ) { const rejectedP = Promise.reject ( '- ' ) ; rejectedP.finally ( ) ; return rejectedP ; } async function test2 ( ) { const rejectedP = Promise.reject ( '- ' ) ; rejectedP.finally...
How is PromiseRejectionEvent triggered ?
JS
I 'm working on a userscript that will make lots of buttons , and I ca n't seem to give them all an unique function.I already tried andBut they do n't work . Then I read somewhere that only the following works : This causes that all the buttons will only downvote the last ID and username of the iteration . I want them ...
downArrow.onclick = function ( ) { downVote ( id , username ) } ; < br > downArrow.onclick = `` downVote ( \ '' '' + id + `` \ '' , \ '' '' + username + `` \ '' ) '' ; downArrow.addEventListener ( 'click ' , downVote ( id , username ) , false ) ; var targetPosts = document.getElementsByClassName ( `` thing message '' )...
How can I make sure the addEventListener does n't ignore the iteration of the i var in my for loop ?
JS
I have a javascript that changes the image scr when you click on the image and it will cycle through . It also had pagination links with arrow keyboard navigation . What I want to do is add a select dropdown list box that allows me jump to any image I want . How can I do this ? I just want a select dropdown list withou...
/* set first image in frame from # shoebox on document.ready */ $ ( function ( ) { var leadOff = $ ( ' # shoebox img : first-child ' ) .attr ( 'source ' ) ; $ ( '.picture ' ) .attr ( { 'src ' : leadOff , 'imageposition ' : ' 1 ' } ) ; } ) ; /* load next image from # shoebox ( click on image and/or next button ) */ $ ( ...
Add select dropdown box to onclick swap image js
JS
I am using an iframe to upload an image . So I have two files - the file for the iframe and the file that will display the image . When the link to display the iframe is clicked this code is run : On the iframe is an upload button that saves the image to a folder on the computer and sets the image file name to FileName...
function ShowUploadImageOut ( RecordID ) { $ ( ' # < % =hfPieceID.ClientID % > ' ) .val ( RecordID ) ; $ ( `` # dvAddImageOutturn '' ) .html ( ' < iframe id= '' iframeUpload '' src= '' utilities/UploadPOD.aspx ? id=uploadOutturn '' > < /iframe > ' ) ; } protected void btnUpload_Click ( object sender , EventArgs e ) { i...
Ca n't find FileHiddenName from iframe
JS
I still do n't have tight grip on promises . Say I have a code : and later I call : It works as excepted -- once the blinking is done , the last fadeOut kicks in . But when I do the blinking via plugin ( with setup to use jQuery animation ) so my entire first part is just one call : the body of blink is : so it is recu...
selected.eq ( i ) // blink .fadeOut ( 200 ) .delay ( 50 ) .fadeIn ( 400 ) .delay ( 100 ) .fadeOut ( 200 ) .delay ( 50 ) .fadeIn ( 400 ) ; selected.unbind ( 'click ' ) .promise ( ) .done ( function ( ) { selected.fadeOut ( 500 ) ; } ) ; selected.eq ( i ) .modernBlink ( { duration : 750 , iterationCount : 3 , auto : true...
Is there a way to control flow of promises in linear call order ?
JS
I am generating some SVG circles using d3.js . I 'm able to generate them , but I ca n't figure how to divide them into 4 equal sections and color fill each section . I 'm using version 4 of d3.js . Here is a snippet of my javascript from my fiddle : Thanks much in advance.https : //jsfiddle.net/pqk8y3mb/
var nodes = [ { `` type '' : 'family ' , '' id '' : 'f1 ' , '' name '' : '' , `` image '' : '' '' } , { `` type '' : 'person ' , '' id '' : 'p1 ' , '' name '' : 'fred flintstone ' , '' age '' : 39 , `` relationship '' : `` father '' , '' sex '' : ' ' } , { `` type '' : 'person ' , '' id '' : 'p2 ' , '' name '' : 'wilma...
How to add filled sections to SVG circles using d3.js
JS
Some of the fields on my form can be multi-line , including , for example , the `` comments '' field . Notice the spacing on the fields after the comments are all ok.because the users can enter multi-line text , I have added the following code to the page , so that it will resize the field appropriately . Basically jus...
function AutoExpandTextbox ( txtbox ) { txtbox.style.height = `` 1px '' ; txtbox.style.height = ( 4 + txtbox.scrollHeight ) + `` px '' ; ResizeFormGroup ( txtbox ) ; } ... . < div class= '' form-group '' > < asp : Label runat= '' server '' AssociatedControlID= '' commentsTextBox '' CssClass= '' col-lg-2 col-md-2 col-sm...
When changing height of html textbox , rest of page gets crowded
JS
I saw a strange behavior.I created a Input.and tried to access it directly from id . Instead of throwing an exception console was showing above input element.After that I tried to compare it with getElementByIdconsole was showing true.You can see this behavior on jsfiddle.Is it a strange behavior or am I missing someth...
< input id='inputid ' value='value'/ > ​ console.log ( inputid ) ; console.log ( inputid == document.getElementById ( 'inputid ' ) ) ;
Element accessible with ID
JS
After a dozen research , still could not solve my problem in showing two graphs on the same page ( with Google Charts ) .I could not figure out what is wrong or what I 'm forgetting , if someone can give me some tips or point me what I 'm missing , I 'll be grateful.I 'm able to show 1 chart , but when I try to show an...
< script type= '' text/javascript '' src= '' https : //www.google.com/jsapi '' > < /script > < script type= '' text/javascript '' > google.load ( 'visualization ' , ' 1.0 ' , { 'packages ' : [ 'corechart ' ] } ) ; //google.setOnLoadCallback ( drawChartAtleta ) ; //google.setOnLoadCallback ( drawChartSexo ) ; google.set...
javascript - How to load two google charts on the same page , different divs
JS
Here 's an example of what I 'm trying to do.I 'm getting an error that says `` Uncaught TypeError : Object # has no method 'displayName ' '' Not really sure why I 'm getting this error . Any help is greatly appreciated .
User = ( name , dob , rank , score ) - > { name : name dob : dob details : { rank : rank score : score } basicInfo : - > return `` Name : # { @ name } - Dob : # { @ dob } - # { @ details.rank } `` detailedInfo : - > return `` Name : # { @ name } - Rank : # { @ details.rank } - Score : # { @ details.score } '' } User : ...
CoffeeScript prototype error
JS
Consider the following Unicode-heavy regular expression ( emoji standing in for non-ASCII and extra-BMP characters ) : Firefox returns [ `` '' , `` '' , `` '' , `` '' , `` '' , `` '' ] .Chrome 52.0.2743.116 and Node 6.4.0 both return null ! It doesn ’ t seem to care if I put the string in a variable and do str.match ( ...
''.match ( /||/ug )
Sequence of logical OR in ES6/Unicode regular expression in Chrome ✗ vs Firefox ✓
JS
What is the most idiomatic way to call all functions in a list ? The best I can think of is : Is there a more idiomatic way of doing this ? EDIT : I 'm really only interested in ES5 for now . Perhaps there is some way having to do with Array prototypes ?
myFunctions.forEach ( function ( f ) { f ( ) ; } ) ;
Call all Javascript functions in a list
JS
I created a diagram with JointJS cells and now I want to change the label of a cell by clicking on it . When I click on a cell a modal pops up and I enter a new text . The text will be stored in a variable . When the modal closes the label of the clicked cell will be changed to the value of the variable.Now the problem...
paper.on ( 'cell : pointerclick ' , handleClickOnCell ) ; function handleClickOnCell ( e ) { $ ( ' # captionModal ' ) .modal ( 'show ' ) ; $ ( ' # captionModal ' ) .on ( 'hidden.bs.modal ' , function ( ) { e.model.attr ( 'label/text ' , labelText ) ; } ) ; } ;
Change label of a JointJS cell by clicking on it and type in a new label
JS
This is a follow up from my previous question.I have a progressbar.js circle that animates on scroll . If there is just one circle it works as expected.Now I want to create many of these animated circles by looping through an object with different key-values pairs.For example : For each key-value pair , the key is a di...
var divsValues = { 'total-score-circle ' : 0.75 , 'general-score-circle ' : 0.80 , 'speed-score-circle ' : 0.85 , 'privacy-score-circle ' : 0.90 , } ; //Loop through my divs and create animated circle for each onefunction makeCircles ( ) { var divsValues = { 'total-score-circle ' : 0.75 , 'general-score-circle ' : 0.80...
When looping through animations , only the last loop runs
JS
i have this html : How to write a jquery selector which give me the price text only `` $ 61.00 '' ? i want to make it generic as i can because may be in some cases there is no inner span , just the parent one .
< span class= '' price '' > $ 61.00 < span class= '' detailFreeShipping '' > With Free Shipping < /span > < /span >
how to select just the top element text ?
JS
So I have this simple module : if I do n't use export default , then the TypeScript compiler will write one warning saying my `` module has no default export '' , which I 'd like to avoid.So to use this module , we would do : that 's all good and well , but what if I want to use CommonJS to import it ? Then I have to d...
export default function ( ) { } import fn from 'my-module ' ; const fn = require ( 'my-module ' ) .default ;
Support ES6 module syntax along with CommonJS
JS
What does the equals in the ng-repeat attribute value mean ? instead of doing : I ca n't see any examples explaining its use in the documentation for ngRepeat .
< li ng-repeat= '' person in people = ( people | orderBy : firstname ) '' > < li ng-repeat= '' person in people | orderBy : firstname '' >
What does equals in ngRepeat do ?
JS
Just wondering , when you use array.length it gets the last index value and adds one . What if you have an array , that is defined this way for some reason : What is the absolute best way to get the true length of this Array ? Something that would return 2 as the value.I was thinking something like this , but not sure ...
var myArray2 = [ ] ; myArray2 [ 10 ] = ' x ' ; myArray2 [ 55 ] = ' x ' ; Array.prototype.trueLength= function ( ) { for ( var i = 0 , ctr=0 , len=myArray2.length ; i < len ; i++ ) { if ( myArray2 [ i ] ! =undefined ) { ctr++ ; } } return ctr ; } console.log ( myArray2.trueLength ( ) ) ;
What is the best way to count absolute array length in JavaScript ?
JS
I am very confused as to why sometimes when I use a combination of an instance of a class with a promise I get two kinds of errors . If I use Promise.all ( ) with a two or three chained promises I only sometimes get a an error of an undefined variable within the callback . When I have a complicated class with multiple ...
'use strict ' ; class Controller { constructor ( ) { this.data = 'data ' ; this.moredata = 'data ' ; this.evenmore = [ ' a ' , ' b ' , ' c ' ] ; this.dataobj = { `` a '' : `` 1 '' , `` b '' : `` 2 '' , `` c '' : `` 3 '' } ; } } //BLOCKED CODE { let cc = new Controller ( ) ; let loadeddata = null ; let xhr = $ .getJSON ...
ES6 Promise and Class conflict
JS
2 questions:1 . How to access to parent 'this ' from jq object ( returnUsers ) ? 2 . Why alert after jq post is calling before some alert in jq post ?
var UsersMenu = function ( ) { this.returnUsers = [ ] ; this.retrieve = function ( posts ) { var temp = [ ] ; $ .post ( `` router.php '' , { `` action '' : `` getUsersMenu '' , `` posts '' : posts } , function ( data ) { if ( data.response ) { for ( var i=0 ; i < data.returnUsers.length ; i++ ) { temp.push ( data.retur...
Object in object
JS
I 've been struggling recently writing a kind of `` speed dating style '' algorithm . The basic goal is for each member of one group ( Men ) to meet each member of the other group ( Women ) at their table , once.The conditions are : The number of tables are equal to the number of women.Each man is assigned to a table w...
var men = [ 'm1 ' , 'm2 ' , 'm3 ' , 'm4 ' , 'm5 ' , ] , women = [ 'w1 ' , 'w2 ' , 'w3 ' ] ; ┃ ROUND 1 ┃ ROUND 2┌─────────────┬─────────────┐ ┌─────────────┬─────────────┐│ men │ women │ │ men │ women │├─────────────┴─────────────┤ ├─────────────┴─────────────┤│ m1 > > > w1 │ │ m4 > > > w1 ││ m2 > > > w2 │ │ m5 > > > w2...
Members of two groups of different size must meet each other ( 1v1 , once )
JS
in javascript , is it possible to make an event handler when a function attribute changes fromto
window.onclick = function ( ) { ... .function 1 ... ... } ; window.onclick = function ( ) { ... .function 2 ... .. } ;
can I find when window.onclick ( ) function overridden ?
JS
I am trying to pull out the license array of numbers for a chart.jsThe shape of the API report data is : Is it possible to destructure like so with fetch ? I am not getting anything back with a console.log ( license ) Thanks for any help !
{ `` report '' : { `` usage '' : { `` chartLabels '' : [ `` ' 1-Mar ' , ' 2-Mar ' , ' 3-Mar ' , ' 4-Mar ' , ' 5-Mar ' , ' 6-Mar ' , ' 7-Mar ' , ' 8-Mar ' , ' 9-Mar ' , '10-Mar ' , '11-Mar ' , '12-Mar ' , '13-Mar ' , '14-Mar ' , '15-Mar ' , '16-Mar ' , '17-Mar ' , '18-Mar ' , '19-Mar ' , '20-Mar ' , '21-Mar ' , '22-Mar ...
what is the correct way to destructure a nested json object with fetch ?
JS
I have a JavaScript closure which I keep recreating throughout the life time of my web application ( single full-ajax page ) .I would like to know if it 's creating a memory leak . Here is an example JSFIDDLEThe code in question :
function CreateLinks ( ) { var ul = $ ( `` < ul > < /ul > '' ) .appendTo ( 'div # links ' ) ; for ( var i in myLinks ) { var li = $ ( ' < li > ' + myLinks [ i ] .name + ' < /li > ' ) .appendTo ( ul ) ; //closure starts here ( function ( value ) { li.click ( function ( e ) { $ ( 'div # info ' ) .append ( ' < label > ' +...
Am i creating a memory leak ?
JS
how i can make the `` .each '' to starts with the div id small number `` 1 '' to the big number `` 5 '' ... 1 / 2 / 3 / 4 / 5lets say i have this divsi have this jquery what im using , but starts with the first div class id number `` 5 '' but i need to start with number 1 ...
< div class= '' TID_5 '' > TID 5 < /div > < div class= '' TID_4 '' > TID 4 < /div > < div class= '' TID_3 '' > TID 3 < /div > < div class= '' TID_2 '' > TID 2 < /div > < div class= '' TID_1 '' > TID 1 < /div > $ ( `` div [ class*='TID_ ' ] '' ) .each ( function ( ) { // code is come here ... } ) ;
How to start .each from div id small to biggest number ?
JS
Looking at this simple code which uses Lazy Expressions : The output here is 2.I must say that I thought it should output 5 . However - this would 've been logical if f was closing over the parameter list scope - if it had a scope.Because looking at this other example ( which a bit related ) : This will output 1 . ( Wh...
var x = 1 ; function foo ( x = 2 , f = ( ) = > x ) { var x = 5 ; console.log ( f ( ) ) } foo ( ) var x = 5 ; var f = function ( ) { return x ; } x = 1f ( ) ; console.log ( x )
Does JS treat parameter list as a scope that can be closed upon ?
JS
I 'm building a site and one particular operation triggers a long , server-side process to run . This operation ca n't be run twice at the same time , so I need to implement some sort of protection . It also ca n't be made synchronous , because the server needs to continue responding to other requests while it runs.To ...
var site = require ( `` express '' ) ( ) ; var exec = require ( `` child-process-promise '' ) .exec ; var busy = false ; site.get ( `` /test '' , function ( req , res ) { if ( busy ) { res.json ( { status : '' busy '' } ) ; } else { busy = true ; // < -- set busy before we start exec ( `` sleep 5 '' ) .then ( function ...
Allowing only one async operation at a time
JS
The book Javascript : The definitive guide states the following in it 's 6th edition , in the chapter 4.13.3 The delete OperatorBut when i tried the above snippet in Firefox and in chrome , the array 's length was still 3.Is this a wrong information from the book or is the implementation of javascript in the browsers d...
var a = [ 1,2,3 ] ; // Start with an arraydelete a [ 2 ] ; // Delete the last element of the arraya.length // = > 2 : array only has two elements now
delete operator in javascript
JS
As part of my learning JavaScript , I try to write code to demonstrate the concept I am learning ; today I 'm learning hoisted variables . Here is the code I wrote : I expected the following results : However , when testing my code at WriteCodeOnline.com and in another sandbox , the first console.log displays A : My na...
console.log ( `` A : My name is `` + name ) ; function happy ( ) { console.log ( `` 1 : I am `` + feeling ) ; var feeling = `` happy '' ; console.log ( `` 2 : I am `` + feeling ) ; } happy ( ) ; var name = `` Jim '' ; console.log ( `` B : My name is `` + name ) ; A : My name is undefined1 : I am undefined2 : I am happy...
Why is my JavaScript hoisted local variable returning undefined but the hoisted global variable is returning blank ?
JS
I 've started to rely on NPM scripts as my main tool for my testing process.As I 've written more NPM scripts the order and structure are increasingly hard to read at a glance.Here is what my current scripts looks like : This is only for around 8 tests or so . I plan on writing scripts to output reports to junit format...
{ `` scripts '' : { `` clean '' : `` rm -rf report/* '' , `` report '' : `` rm -rf report/ ; mkdir report '' , `` tests : mocha '' : `` mocha test/spec/ '' , `` all-tests : mocha '' : `` npm run tests : mocha -- -- recursive '' , `` all-tests : json '' : `` npm run all-tests : mocha -- -- reporter json '' , `` all-test...
Is there a better way to structure my NPM scripts so they are more readable ?
JS
There are two elements inside a container - one ( blue ) needs to stay to the left , and the other one ( green ) is centered relative to the outer red . However , if the screen is small enough , the centered container ( green ) can not overlap with the container on the left ( blue ) , it should always stay to the right...
< div class= '' red '' > < div class= '' blue '' > texttexttexttext < /div > < div class= '' centered '' > Centered Container of fixed width < /div > < /div > .red { height : 100px ; text-align : center ; border : 3px solid red ; position : relative ; } .blue { background : blue ; height : 100 % ; float : left ; } .cen...
Center element until it meets an obstacle
JS
Given : is : exactly equivalent to : ? Thanks
function A ( name ) { this.name = name ; } var a1 = new A ( `` A1 '' ) ; var a1 = { } ; A.call ( a1 , `` A1 '' ) ; a1.__proto__ = A.prototype ;
Are these two ways of constructing an object in JavaScript equivalent ?
JS
I have a table where clicking a link should show 'subrows ' that belong to the data in the row clicked.Since the subrows number may vary from 0 to n I think I should calculate the number of subrows by the .val method , is this right ? So the value should be the number of invisble rows with class name 'affiliated ' unti...
var affiliatednumber = $ ( this ) .find ( `` tr.affiliated '' ) .val ( ) .stop ( ) ;
Toggle variable number of table rows
JS
I 'm trying to understand async & defer HTML 5 attributes . Here is my testing code : script.js : As I understand , and according to the definition , `` defer ... specifies that the script is executed when the page has finished parsing '' should n't the output be : instead ofwhich is the case ? Why does the document.wr...
< body > < script type= '' text/javascript '' src= '' script.js '' **defer** > < /script > < div id= '' div1 '' > Abc < /div > < /body > document.write ( `` Hello World ! '' ) AbcHello World ! Abc
HTML 5 defer attribute
JS
I found something very odd today : If you create objects with a constructor function and the new keyword , but return a function from the constructor , it behaves like so : The newly-created `` object '' is instead a function.That new function can be invoked like normal , however ... If you maintain a reference to this...
function Constructor ( ) { var self = this ; this.name = 'instance ' ; return function ( ) { return self ; } } typeof instance //returns `` function '' typeof instance ( ) //returns `` object '' instance ( ) //returns { name : 'instance ' }
Using 'return ' when creating objects with 'new '
JS
On a couple of polyfill examples in MDN for some Array prototype functions , there are the following two lines ( e.g . : https : //developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find ) : I presume the first example is autoboxing ( ? ) . But what is its purpose either way if this is alway...
var list = Object ( this ) ; var length = list.length > > > 0 ; var length = list.length || 0 ;
What does Object ( [ ] ) ; do ?
JS
Why do programming languages have a NaN value ? Why not just throw a TypeError ? The question is tagged both javascript and language-agnostic because JavaScript is the language I am primarily familiar with , but I know this applies to other languages as well .
Math.floor ( 'string ' ) ; // -- > NaN TypeError : Expected number instead of string
Why do we need the NaN value when we can throw TypeErrors ?
JS
As far as I understand , in JavaScript ( Gecko variant ) this : is a syntactic sugar for something like this : Because of that , A ( ) ( which is equivalent to A.call ( ) ? ) and new A ( ) should produce two different results , like these : So far so good.But , core object Function behaves differently : Am I missing so...
var a = new A ( ) ; var a = { } ; a.__proto__ = A.prototype ; A.call ( a ) ; > > > new Date ( ) Fri Nov 19 2010 01:44:22 GMT+0100 ( CET ) { } > > > typeof new Date ( ) '' object '' > > > Date ( ) '' Fri Nov 19 2010 01:44:42 GMT+0100 ( CET ) '' > > > typeof Date ( ) '' string '' > > > Function ( 'return 123 ; ' ) anonym...
JavaScript - behaviour of Function core object
JS
I am trying to create a regex that I can use to remove any closing comment syntax out of string . For instance if I had : /* help : :this is my comment */ should return this is my comment or < ! -- help : : this is my other comment -- > should return this is my other comment . Ideally I would like to target all major p...
function RemoveEndingTags ( comment ) { return comment.split ( 'help : : ' ) [ 1 ] .replace ( `` */ '' , `` '' ) .replace ( `` -- > '' , `` '' ) ; //my ugly solution } < ! -- help : : This is a comment -- > < div > Hello World < /div >
Regex to remove comments endings
JS
I have the following listener setup in my Unity scene : And in my web view I have this log function : When I execute the following code , the only output that shows up in logcat are tests 5 and E : What is causing this and how can it be fixed ?
ui.OnMessageReceived += ( view , message ) = > { var path = message.Path ; var action = message.Args [ `` action '' ] ; if ( path == `` app '' ) { if ( action == `` log '' ) { Debug.Log ( `` [ W ] `` + message.Args [ `` text '' ] ) ; } } } ; log : function ( m ) { window.location.href = 'uniwebview : //app ? action=log...
UniWebView message throttling/collision ?
JS
I have two input fields one for advance payment and other for full payment , which are fetched from the database in array.If onchange or keyup the advance payment is greater than full payment , Then the advance payment should not be entered or should be equal to full payment.I am trying with this code
< input type= '' text '' value= '' < ? php echo $ full_payemnt ; ? > '' id= '' full_payment_ < ? php echo $ i ; ? > '' > < input type= '' text '' id= '' advance_payment_ < ? php echo $ i ; ? > '' class= '' advance '' > $ ( '.advance ' ) .on ( 'change keyup blur ' , function ( e ) { var fullPay = $ ( ' # full_payment_'+...
Input field value should not be greater than other field value
JS
With the flow.js component we can assign a browse button like this : We can assign a drop area like this : We can also unassign a drop area like this : My first question is how to unassign a browse button ? My second question is how to know ( natively ) if a browse button is already defined ? I ca n't see any info on t...
flow.assignBrowse ( document.getElementById ( 'browseButton ' ) ) ; flow.assignDrop ( document.getElementById ( 'dropTarget ' ) ) ; flow.unAssignDrop ( document.getElementById ( 'dropTarget ' ) ) ;
Unassign browse button on the flow.js HTML5 upload component
JS
There is a JSON search engine here . I am trying to figure out how I can filter the results of a google sheet to just include items with characters of less than 4 and more than 7 , for example : So in jQuery I did this : Then I assumed that it had to go into an if statement ( as per suggestion in comments ) but the if ...
entry.filter ( entry = > entry.gsx $ status. $ t.length > 7 || entry.gsx $ status. $ t.length < 4 ) mounted : function ( ) { var entry = data.feed.entry ; var result = entry.filter ( entry = > entry.gsx $ status. $ t.length > 7 || entry.gsx $ status. $ t.length < 4 ) ; $ .ajax ( { dataType : `` json '' , url : GSHEET_J...
Filter JSON results with jQuery
JS
I have these 4 HTML snippets : Siblings : Wrapped 1 : Wrapped 2 : Separated : How can I , with jQuery , select the next .b element for any given .a element , regardless of nesting ? I want something like this :
< div class= '' a '' > ... < /div > < div class= '' b '' > ... < /div > < ! -- selected -- > < div class= '' b '' > ... < /div > < ! -- not selected -- > < div class= '' a '' > ... < /div > < div > < div class= '' b '' > ... < /div > < ! -- selected -- > < /div > < div class= '' b '' > ... < /div > < ! -- not selected ...
Is there a jQuery selector to accomplish this task ?
JS
I have a problem synchronizing the loading of scripts and executing them with jQuery.What I have looks similiar to this : loadJSFile loads a javascript file via $ .getScript , if it 's not already included in in the DOM , returning the $ .getScript Promise , or not returning anything , if it 's already included.I think...
// Load Libraries in 'when ' $ .when ( loadJSFile ( `` lib1.js '' ) , loadJSFile ( `` lib2.js '' ) loadJSFile ( `` lib3.js '' ) ) .then ( function ( ) { // Load JS files that use the library files loadJSFile ( `` file1.js '' ) ; loadJSFile ( `` file2.js '' ) ; loadJSFile ( `` file3.js '' ) ; // needs to return deferred...
jquery multiple deferreds in then
JS
I 've been trying to set up a website that plays a random .webm that loops , then when you press a key , it plays the next random .webm . I got the random part down , but I ca n't seem to figure out how to get it to wait for the keystroke . Another issue I 'm having is that I ca n't figure out how to get it to load a r...
< ! DOCTYPE html > < html > < head > < title > webm haha < /title > < link rel= '' stylesheet '' type= '' text/css '' href= '' main.css '' > < /head > < body > < video controls loop id= '' video1 '' src= '' data/1.webm '' autoplay > < /video > < script type= '' text/javascript '' src= '' lib/jquery-2.2.0.min.js '' > < ...
Is there a way to skip a currently playing video ( with a keystroke ) and continue to the next video ?
JS
I 'm kind of curious why this does n't workJavaScript : HTML : Is evaluate a reserved keyword somewhere on the html side ?
function evaluate ( ) { console.log ( 42 ) ; } < a onclick= '' evaluate ( ) '' > Click Me ! < /a >
Why Ca n't I Use JS Function Called 'evaluate ' in HTML ?
JS
On my webpage I have a div . On that div I have `` animation '' that simulates the div being turned over ( flipped ) .I rotate the `` wrapper '' div with the jQuery plugin transit . What the plugin does is just apply the CSS ; When the div is on rotateY ( 90deg ) , I have to load some new content in the # content div ....
< div id= '' wrapper '' > < div id= '' content '' > Some content < /div > < /div > transform : rotateY ( 180deg ) ;
How to make the div not dissapear when rotateY ( 90deg )
JS
When arrays are assigned to another variable , the reference is passed as opposed to values . This is confirmed when you compare two arrays using == operator and it returns trueWith the above inputs , when I modify the array b , it mutates array a , but not c.But when I do the below , it mutates c.Why does this happen ...
var a = [ [ 1,2 ] , [ 3,4 ] , [ 5,6 ] ] ; var b = a ; // b = [ [ 1,2 ] , [ 3,4 ] , [ 5,6 ] ] var c = [ ] .concat ( a ) ; // c = [ [ 1,2 ] , [ 3,4 ] , [ 5,6 ] ] a == b ; //truea == c ; //false b.push ( [ 7,8 ] ) ; // b = [ [ 1,2 ] , [ 3,4 ] , [ 5,6 ] , [ 7,8 ] ] a ; //a = [ [ 1,2 ] , [ 3,4 ] , [ 5,6 ] , [ 7,8 ] ] c ; //...
What am I missing with the understanding of Arrays ?
JS
Problem : I ca n't seem to find a satisfactory explanation of why javascript Maps need square brackets for the JSON.stringify method to `` reach '' ( ? ) into the nested elements . I think I 'm missing something about ES6 , or something inherent to the Map data type . I can convert the Map to an object , and stringify-...
const blah = new Map ( ) ; blah.set ( ' u ' , { 'something ' : [ { 'hey':98 } , 56 , 'bob ' ] } ) ; blah.set ( { 'hey ' : { 'hey ' : 78 } } , 'what ? ' ) ; console.log ( JSON.stringify ( ... blah ) ) ; // [ `` u '' , { } ] //I thought this would yield the result of the below console.logconsole.log ( JSON.stringify ( [ ...
Why are square brackets needed to stringify all elements of a Map in Javascript ?
JS
I have a code based on Bootstrap 3.3.7There are different menu items and sub menus on my menu , I want to have all sub menu items to be open on mobile , Means no need to click on any menu items to display it 's sub menus , So I wrote a JS code to open all sub menus on mobile : But the problem is when I click on a navba...
function opensubmenus ( ) { if ( $ ( window ) .width ( ) < 768 ) { $ ( `` # top-navbar-collapse li '' ) .addClass ( 'open ' ) ; } else { $ ( `` # top-navbar-collapse li '' ) .removeClass ( 'open ' ) ; } } $ ( window ) .resize ( opensubmenus ) ; opensubmenus ( ) ;
Bootstrap Avoid navbar-toggle button to close opened sub menus on mobile
JS
Say you have 2 identical functions that do not return a valueFunction b is obviously more verbose but is there any functional difference between these ?
function a ( ) { // do some interesting things } function b ( ) { // do the same interesting things return ; }
Is there a difference between a function with and without a return statement ?
JS
I have a JS script that appends to the HTML page the pairs : input + anchorCan I compute the URL before the redirect happens ? Now I have link that looks like this : and myFunct uses window.location.href to redirect webpage . The problem with this approach is that I can not ( obviously ) CTRL+click on the link for open...
< a href= '' # '' onclick= '' myFunct ( ) ; return false ; '' > link < /a >
Anchor with `` computed '' URL
JS
Let 's say I have these three documents : I have a cloud database and then I have a device with pouchDB syncing from that database.These are the steps that I do : I sync both databases together . So now I have the most recent versions of this document on my device.I run the below query and I get back all three template...
{ `` _id '' : `` 11111 '' , `` type '' : `` template '' , `` name '' : `` person '' } { `` _id '' : `` 22222 '' , `` type '' : `` template '' , `` name '' : `` place '' } { `` _id '' : `` 33333 '' , `` type '' : `` template '' , `` name '' : `` thing '' } var template_obj = { } ; return device_db.query ( 'filters/templ...
pouchDB query ( ) bug when updating documents
JS
I am using bar-ui js of soundmanager.I have many players so what i need.I want to select sound id from html class using jQuery ... I that possible ? ? ? Like i am using content class in the above code so i can apply some custom changes that..UpdateSee here are many players And here is example of soundmanager2 code
< div id= '' sm2-99943 '' class= '' sm2-bar-ui content compact flat full-width playlist full-width-player `` > < div class= '' bd sm2-main-controls '' > < div class= '' sm2-inline-element sm2-button-element '' > < div class= '' sm2-button-bd '' style= '' background : transparent url ( http : //support.simplepodcaster.c...
Get soundManager soundId from class using jQuery
JS
The title of this question is probably misleading . I 'm having some trouble wrapping my head around this concept . I want to pass all of the arguments into a function , but call it with those arguments later.I 'm currently doing something like this : This is where I would save and later call the function : I need to d...
function copyRecords ( userId , options ) { const getRecordsWrapper = ( userId , options ) = > ( ) = > getRecords ( userId , options ) ; abstractionService = new MyAbstractionService ( getRecordsWrapper ) ; ... etc } class MyAbstractionService { constructor ( getRecords ) { this.getRecords = getRecords ; } performSomeA...
Save arguments for later Javascript
JS
I have this class : The class is called in a loop : My question is , is there a way to call a method once the loop has completed and self.fileRead has returned it 's deferred for everything in the loop ? I want it to call the method even if one or more of the deferred fails .
( function ( ) { `` use strict '' ; var FileRead = function ( ) { this.init ( ) ; } ; p.read = function ( file ) { var fileReader = new FileReader ( ) ; var deferred = $ .Deferred ( ) ; fileReader.onload = function ( event ) { deferred.resolve ( event.target.result ) ; } ; fileReader.onerror = function ( ) { deferred.r...
Call a method once all deferred completes ?
JS
I want to create a little HTML extension which provides a tag ( uai ) which will be formatted like < uai src= '' some_what_file.mp3 '' controller= '' nav '' autoplay= '' true '' > And so on this tag will get a javascript object assigned.But I wonder how I will apply this function as an object to the html tag and make t...
function uai ( ) { this.src = { ... } this.controller = { ... } this.autoplay = { ... } }
Making a HTML source object
JS
I have the following code : And now the question is : if I want get links by the first-level iframe , how should I refactor the getLinksFromIframes ( ) function . Currently they share a 'global ' variable links . I think definitely the links will be list of link list and initialize new list within withFrame function , ...
var casper = require ( `` casper '' ) .create ( { // verbose : true , // logLevel : `` debug '' , webSecurityEnabled : false } ) ; var links = [ ] ; function get_links ( obj ) { return obj.evaluate ( function ( ) { var i , l = document.querySelectorAll ( `` a '' ) , l2 = [ ] ; for ( i = 0 ; i < l.length ; i++ ) { l2 [ ...
Group nested links by first-level iframe using casperjs
JS
I do n't understand what it means when you have ( ) around the whole expression ? What does it do ?
( { body : { customer } } = await callCreateCustomer ( { email : createRandomEmailAddress ( ) , key : 999 , password : 'password ' , } ) ) ;
What is this javascript syntax where you have ( ) around the whole variable expression ?
JS
Warning : Buggy JavaScript code first ! As it can be seen , the this in increment_helper rather refers to the global scope ( or to window scope to be precise IF I 've got it right ) instead of referring to the this of the enclosing closure . So that , the output will be : 0instead of 1I 'll list the better ( still not ...
// 1 : buggy counter// -- -- -- -- -- -- -- -- -// problem : 'this ' can be `` broken '' var Counter1 = function ( ) { this.count = 0 ; this.increment = function ( ) { function increment_helper ( ) { ++this.count ; // this refers to window ( global ) , not to the object that Counter1 was called with } increment_helper ...
Why 'this ' resolution is so special in JavaScript ?
JS
I 'm modifying a piece of code in 3 ways . In these 3 conditions in is behaving differently . Please describe how it 's executing ? Why in 2nd case it 's printing undefined ? And in 3rd case I 'm sending my global a as an argument , then also it 's printing undefined .
var a=1 ; function myFunc ( ) { console.log ( a ) ; console.log ( a ) } myFunc ( ) ; //Output is:1 1var a=1 ; function myFunc ( ) { console.log ( a ) ; var a=2 ; console.log ( a ) } myFunc ( ) ; //Output is : undefined2var a=1 ; function myFunc ( ) { console.log ( a ) ; var a=2 ; console.log ( a ) } myFunc ( a ) ; //Ou...
Why this strange behavior ?
JS
In the code belowWhy is it that when console.log ( x ) , x is undefined ?
var x = 1 ; ( function ( ) { console.log ( x ) ; var x = 2 ; } ( ) ) ;
Why is x undefined in inner scope ?
JS
I want to replace this `` 】| '' character from string with this '' 】 '' . mystring is = '' 【権利確定月】|1月 '' and desired output is `` 【権利確定月】1月 '' .I have tried with array operation and also with this code : but not working.I only want to this with sequence for '' 】| '' .Because after that string will grow like thisexample...
mystring.replace ( /】|/g , '】 ' )
Javascript replace on multiple Japanese character
JS
I 'm trying to learn to work with jquery.scombobox but I 'm stuck when adding the scombobox to a modalFor multiple items it adds a scrollbar in the right . I can scroll trough the items by using the mouse scroll wheel but when trying to click on the scrollbar and dragging it , the dropdown collapses . Did anyone encoun...
< div id= '' modalA '' class= '' modal '' tabindex= '' -1 '' role= '' dialog '' aria-labelledby= '' myModalLabel '' aria-hidden= '' true '' > < div class= '' modal-dialog '' > < div class= '' modal-header '' > < button type= '' button '' class= '' close '' data-dismiss= '' modal '' aria-hidden= '' true '' > × < /button...
Chrome - if jquery-simple-combobox is inside a modal collapses when mouse dragging
JS
I need my code to run x amount of times and then pause for 30 seconds or so before resuming . Any ideas ?
myslidefunction ( ) ; var tid = setInterval ( myslidefunction , 1000 ) ; function myslidefunction ( ) { setTimeout ( function ( ) { //do stuff } , 400 ) ; } ;
Run setInterval several times , then pause for several seconds
JS
I am following the https : //devcenter.heroku.com/articles/direct-to-s3-image-uploads-in-rails # jquery-file-upload-callbacks Tutorial to use s3_direct_upload on local development environment . There 's some javascripts which set the fileupload function for each file fields . It all works great if I simply include the ...
ActionView : :Template : :Error ( undefined method ` url ' for nil : NilClass ( in /s3_direct_upload_gem_test/app/assets/javascripts/s3_direct_upload.js.erb ) ) : 18 : 19 : < % = @ s3_direct_post.url % > 20 : 21 : < % = javascript_include_tag : s3_direct_upload % > app/assets/javascripts/s3_direct_upload.js.erb:14 : in...
Asset pipeline can not return @ variables while using ruby coding in .js.erb in Rails
JS
I understand how to define functions like this : But not this : The above is a part of a library I 'm using , but I simply ca n't understand the $ .fn.idle bit . What is it doing ? It 's defining a function called 'idle ' , somehow , but what about the $ .fn ? And what about the ( function ( $ ) { part ? Again , I unde...
function myfunc ( x , y , z ) { alert ( `` Just an example `` + x + y + z ) } < script src= '' http : //ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js '' > < /script > < script > ( function ( $ ) { $ .fn.idle = function ( x , y , z ) { alert ( `` Just an example `` + x + y + z ) } ( jQuery ) ) ; < /script >
What is the significance of this function definition ?
JS
Can someone explain this function ? I understand the result it produce : But do not understand process of creating this functions , I mean part bind ( Function.prototype.bind )
var bindbind = Function.prototype.bind.bind ( Function.prototype.bind ) ; var bindedContextFunc = bindbind ( function ) ( context ) ; bindedContextFunc ( args ) ;
Explain bindbind ( ) function
JS
I was trying this matchand got : while I was expecting : I had no luck until I removed the global flag , which I did not think would impact results my results ! With the global flag removed , produced : which is cool , but reading the docs I ca n't figure out : Why the first form did n't workWhy the global flag interfe...
'/links/51f5382e7b7993e335000015'.match ( /^\/links\/ ( [ 0-9a-f ] { 24 } ) $ /g ) [ '/links/51f5382e7b7993e335000015 ' ] [ '/links/51f5382e7b7993e335000015 ' , '51f5382e7b7993e335000015 ' ] '/links/51f5382e7b7993e335000015'.match ( /^\/links\/ ( [ 0-9a-f ] { 24 } ) $ / ) [ '/links/51f5382e7b7993e335000015 ' , '51f5382...
Why does n't String.match ( ) produce expected results when a global flag is present ?
JS
I have the following code inside an Angular application , the html looks like so.That onSubstringSelect is in the .ts part of the component : I was expecing that I had first the alert ( `` 1st alert '' ) ; and then alert ( `` 2nd alert `` + dataPois ) ; but that alert is executing first . Why ?
< ng-multiselect-dropdown ( onSelect ) = '' onSubstringSelect ( $ event ) '' > < /ng-multiselect-dropdown > onSubstringSelect ( item : any ) { const dataPois = this.getPois ( data ) ; alert ( `` 2nd alert `` + dataPois ) ; // etc } getPois ( data ) : any [ ] { this.api.getPois ( data ) .subscribe ( ( result : any ) = >...
TypeScript and Angular , order of execution in this
JS
I 'm trying to learn Angular 2 using free video tutorials from scotch.io website . I followed the most parts without any problems . But I can not work out passing data from one component to another.There is app.component.html in which it lists user profiles . When the user clicks the user link it should show text input...
< header > < nav class= '' navbar navbar-inverse '' > < div class= '' navbar-header '' > < a href= '' / '' class= '' navbar-brand '' > My Angular 2 App < /a > < /div > < /nav > < main > < div class= '' row '' > < div class= '' col-sm-4 '' > < div *ngIf= '' user_list '' > < ul class= '' list-group users-list '' > < li c...
Angular Pass data using Input component
JS
I 've just come across a strange behavior from Angular : Here 's the scenario : In a registration form , I want to check for email uniqueness ( through an http call to server ) .Thus , I created a directive called emailUnique whose client code is : For the rest of the post , let 's suppose that user is typing : michael...
< form name= '' form '' novalidate > < ! -- some other fields -- > < input name= '' email '' type= '' email '' ng-model= '' user.email '' required email-unique/ > < /form > angular.module ( 'directives.emailUnique ' , [ ] ) .directive ( 'emailUnique ' , function ( ) { return { restrict : ' A ' , require : 'ngModel ' , ...
When Angular directive 's name really matters
JS
I know question is quite simple for you people to answer but , I got stuck at a drop list from where i wanted to select the birth Month.I have been working on other websites but unfortunately could'nt get this to work.I tried : Click using different locators.Using Action class to mover hover and clicking.Using Java Scr...
< span id= '' BirthMonth '' class= '' form-error '' aria-invalid= '' true '' > < div class= '' goog-inline-block goog-flat-menu-button jfk-select '' role= '' listbox '' style= '' -moz-user-select : none ; '' aria-expanded= '' false '' tabindex= '' 0 '' aria-haspopup= '' true '' aria-activedescendant= '' :0 '' title= ''...
Unable to select the value from the drop list
JS
I want to use a library ip-address with SystemJS ( note , this question may look similar but it is a different problem I ran into trying while trying to accomplish this task ) .The library ip-address depends on util-deprecate . It imports it as follows : And then uses it as follows : When I import ip-address in a node ...
var util = require ( 'util ' ) ; Address4.prototype.toV6Group = util.deprecate ( Address4.prototype.toGroup6 , 'deprecated : ` toV6Group ` has been renamed to ` toGroup6 ` ' ) ; var ipAddress = require ( 'ip-address ' ) ; System.import ( 'ip-address ' ) ; util.deprecate is not a function const map : any = { 'ip-address...
`` Namespacing '' an import in systemJS
JS
While playing with the Developer Console in Firefox , I tried doing this : and then this : I expected the result to be function ( ) ( corresponding to c = > c ) , but this was displayed instead : What is the meaning of this expression ? It clearly is n't legal Javascript , since neither / nor < are valid characters for...
var a = b = > c = > c ; a ( 1 ) function a/ < ( ) var a = b = > c = > d = > d ; a ( 1 ) a/ < / < ( )
What 's this `` function a/ < ( ) '' in the developer console ?
JS
I was doing the benchmarking of MongoDB 3.2.17 for fun and can not understand the reason for this behavior.When I create an empty collection prior to doing insertion MongoDB x 906 ops/sec ±2.78 % ( 75 runs sampled ) When I do n't create any empty collection and just simply run insertMany MongoDB x 87.81 ops/sec ±94.31 ...
var Benchmark = require ( 'benchmark ' ) ; var suite = new Benchmark.Suite ; const MongoClient = require ( 'mongodb ' ) .MongoClient ; var collectionMongodb = 'testrecords2 ' ; Promise.all ( [ MongoClient.connect ( 'mongodb : //localhost:27017/testme ' ) ] ) .then ( ( clients ) = > { var nativeCollection = clients [ 0 ...
Why is MongoDB slower to insert Records only when collection does not exist ?
JS
Here is a working example of Decorator pattern : However , if we change the get function to : we will be faced with an error : VM68418:6 Uncaught RangeError : Maximum call stack size exceeded at Dummy.instance.run ( :6:32 ) Why is this happening ? The instance.run is still a wrapper around the original method , without...
class Dummy { run ( ) { console.log ( 'run ' ) ; } } function get ( ) { let instance = new Dummy ( ) ; instance.run = ( ( func ) = > { return function ( ) { func ( ) ; console.log ( 'decorator run ' ) ; } } ) ( instance.run ) ; return instance ; } let obj = get ( ) ; obj.run ( ) ; function get ( ) { let instance = new ...
JavaScript Decorator pattern . Error : Maximum call stack size exceeded
JS
Does adding a property to an array with dot notation change it to an object ? is it an array ? I do n't think so , but underscore.js says it ishttp : //jsfiddle.net/wZcyG/
var arr = [ ] ; arr.something = `` test '' ; console.log ( _.isArray ( arr ) ) ; //true
changing an array to an Object ( upper case ) by adding a value using a dot
JS
I have created a Knockout binding to be able to toggle KML layers with Google Maps , but the solution seems a bit slow and `` flickerish '' . How can I avoid re-creating the map and layers on each toggle ? A running demo can be found here
var ViewModel = function ( ) { var self = this ; self.mapOptions = { center : new google.maps.LatLng ( 60.390791 , 5.306396 ) , zoom : 2 } ; self.levels = [ { text : `` Type 1 '' , countries : ko.observableArray ( [ 'https : //dl.dropbox.com/u/2873968/countries-kml/afghanistan.kml ' , 'https : //dl.dropbox.com/u/287396...
How to toggle KML layers using Knockout.js without re-creating the map ?
JS
I 'm using in a project the following code which is not working : but if I add at the end ( ) it works : My question is , what 's the difference ? What does the ( ) at the end ? I presume that the first one does n't work because somewhere else the `` onload '' has been already called killing this one.Would it have the ...
window.onload=function ( ) { //code here } ; window.onload=function ( ) { //code here } ( ) ;
Differences between window.onload = function ( ) { .. } / window.onload = function ( ) { .. } ( ) ;
JS
How to convert a string to JSON with javascript or jQuery ? I 've been thinking all day , but I do not get a good idea . This task is to dynamically create the treeview in the client side ( ASP.Net ) . My idea is to convert the string to an object and convert to JSON type . ( String - > object - > JSON ) I tried , but ...
var sString = `` A//a1 , A//a2 , A//a3//a31 , A//a3//a32 , B , C//c1 , C//c2 '' ; { `` title '' : `` A '' , `` key '' : `` 1 '' , `` folder '' : true , `` children '' : [ { `` title '' : `` a1 '' , `` key '' : `` 2 '' } , { `` title '' : `` a2 '' , `` key '' : `` 3 '' } , { `` title '' : `` a3 '' , `` key '' : `` 4 '' ...
How to make string to json with javascript ? ( like A//a1 , A//a2 , A//a3//a31 .. )
JS
I am trying to create a directive for custom fields in the form . I am able to create directive but not able to update scope.See Plunker demo for more idea about problemIssue I am facing is when I am submitting the form I am getting a value of custom field ng-model is null or undefined . because Two Way Binding is not ...
< custom-field ng-repeat= '' ( key , field ) in custom_fields '' form= '' userForm '' ng-model= '' user.custom_field [ field.id ] '' fielddata= '' field '' > < /custom-field > app.directive ( 'customField ' , function ( ) { var directive = { } ; directive.restrict = ' E ' ; directive.templateUrl = 'app/modules/custom_f...
Directive for custom fields in form [ scope is not updating ]