lang stringclasses 4
values | desc stringlengths 2 8.98k | code stringlengths 7 36.2k | title stringlengths 12 162 |
|---|---|---|---|
JS | I have a modal to update data . When the update is complete the modal closes and I can not scroll on the page afterwards . modaljavascriptcontrollerI do n't know what is happening . I have used the same modal and script elsewhere and it works fine there . | < div id= '' catupdate '' class= '' modal fade '' role= '' dialog '' > < div class= '' modal-dialog '' > < ! -- Modal content -- > < div class= '' modal-content '' > < div class= '' modal-header '' > < button type= '' button '' class= '' close '' data-dismiss= '' modal '' > & times ; < /button > < h4 class= '' modal-ti... | Can not scroll on page after modal closes |
JS | I have an array of js objects which look like this : I wan na create a new array where the country is unique , but also the dates should be summed.I have problems getting my head around it.Do I have to filter first , reduce it somehow , remap it , ... I 've no idea to start ? Any help would be appreciated , thank you ! | var objArr = [ { `` Country '' : `` US '' , `` City '' : `` MyCity1 '' , `` 2017-07-12 '' : `` 1 '' , `` 2017-07-13 '' : `` 2 '' } , { `` Country '' : `` US '' , `` City '' : `` MyCity2 '' , `` 2017-07-12 '' : `` 2 '' , `` 2017-07-13 '' : `` 2 '' } , { `` Country '' : `` CN '' , `` City '' : `` MyCity1 '' , `` 2017-07-... | How to sum values in array by specific object key ? |
JS | Here 's an excerpt from Chapter 2 Names : A name can not be one of these reserved words : ... delete ... Then later in that section : Names are used for ... property names ... If that 's true , then why does this work in my browser console : I 'm using `` Version 36.0.1985.143 m '' of Google Chrome for my browser and W... | > a = { } ; > a.delete = 1 ; > a.delete + 2 === 3true | `` JavaScript : The Good Parts '' - Why can delete be used as a property name when the book implies it should n't |
JS | I have some html using Vue.js here : I have the javascript here : I want to set class to tabs.active since I 'm using bootstrap . How can I do that ? | < div id= '' app '' > < ul class= '' navbar-nav '' > < li class= '' nav-item '' v-for= '' tab in tabs '' > < a href= '' # '' class= '' nav-link '' > { { tab.name } } < /a > < /li > < /ul > < /div > var app = new Vue ( { el : ' # app ' , data : { tabs : [ { name : `` Home '' , active : `` '' } , { name : `` Challenges '... | Vue.js dynamic classes |
JS | I want to add these scripts in my Layout page | < script src= '' ~/angular/runtime* '' > < /script > < script src= '' ~/angular/polyfills* '' > < /script > < script src= '' ~/angular/vendor* '' > < /script > < script src= '' ~/angular/main* '' > < /script > | How to include js file without knowing proper name in Asp.Net Core |
JS | A pet peeve of mine in programming languages is taking the arguments passed in a constructor , and assigning them directly to fields in a class , named the same thing as the arguments I gave them in the constructor , like so : In order to get around this , I figured out I could create a function that took the existing ... | class A { constructor ( a , b ) { this.a = a ; this.b = b ; etc ... } } function test ( values ) { Object.keys ( this ) .map ( ( x , i ) = > this [ x ] = values [ i ] ) ; } class ChildObj { a1 ; a2 ; constructor ( ) { test.call ( this , arguments ) ; } } A.constructor = function ( ) { test.call ( this , arguments ) ; }... | Is it possible to assign the same constructor to many classes , while maintaining access to their defined fields ? |
JS | Looking at the example given on this MDN pageWhy , when I log o , why do I : Not see it in node.js ? See it but it 's greyed out in Chrome ? | const o = { a : 0 } ; Object.defineProperty ( o , ' b ' , { get : function ( ) { return this.a + 1 ; } } ) ; console.log ( o.b ) // Runs the getter , which yields a + 1 ( which is 1 ) console.log ( o ) | Why do n't we see ' o 's ' b ' property when we log ' o ' ? |
JS | I have an input type= '' file '' and an input type= '' text '' . When I choose the file first and then put text in the input box and click the Add button , the picture does n't show but when I put the text first and then choose the picture ( file ) , it behaves normally.I think there 's some problem in the inputKey Tha... | function Admin ( props ) { const [ productName , setproductName ] = React.useState ( `` '' ) ; let [ productPicture , setproductPicture ] = React.useState ( { file : null , inputKey : Date.now ( ) } ) ; return ( < div > < Link to= '' / '' > Go back < /Link > < br/ > < br/ > < input type= '' file '' onChange= { ( e ) = ... | Input type= '' file '' showing weird behavior when used along with another input type |
JS | I have a page where when a user holds down a key , in my case [ Ctrl ] , they are able to interact with page elements in specific ways . Once they release the key , and the keyup event fires , I reset some flags . I found though that when I click on a select dropdown while holding the key down , the keyup event is neve... | $ ( document ) .on ( `` keydown '' , e = > { if ( e.keyCode == `` 17 '' ) { $ ( `` span '' ) .text ( `` true '' ) ; } } ) ; $ ( document ) .on ( `` keyup '' , e = > { if ( e.keyCode == `` 17 '' ) { $ ( `` span '' ) .text ( `` false '' ) ; } } ) ; select { width : 250px ; height : 35px ; } span { color : red ; } < scrip... | Keyup Event Missed If Clicking On Select ( Dropdown ) |
JS | I want to reprogram my Blackberry convenience key using Cordova . I get the above code to handle the volume keys . But how can I handle blackberry convenience key in Cordova ? Any help will be appreciated | document.addEventListener ( `` volumeupbutton '' , onVolumeUpKeyDown , false ) ; function onVolumeUpKeyDown ( ) { // Handle the volume up button } | Cordova blackberry convenience key |
JS | Is `` function '' a JavaScript type ? For example : Which suggests that `` function '' is indeed a typeHowever , in this ECMAscript documentation it says : The ECMAScript language types are Undefined , Null , Boolean , String , Symbol , Number , BigInt , and Object ” .Could someone explain this to me ? Thanks in advanc... | console.log ( typeof alert ) // returns function | Is “ function ” a JavaScript type ? |
JS | I 'm confused as to why I can not get this service call to perform as needed . The console.log 's within definitionsService.get promise resolution are what I would expect ( the object I 'm aiming to return ) . However the console.log right before I return defs is undefined which , of course , means my returned value is... | function getDefinitions ( ) { var defs ; definitionsService.get ( ) . $ promise.then ( function ( data ) { console.log ( data ) ; defs = data ; console.log ( defs ) ; } ) ; console.log ( defs ) ; return defs ; } ; function getDefinitions ( ) { var defs = $ q.defer ( ) ; definitionsService.get ( ) . $ promise.then ( fun... | Scoping within Angular service call |
JS | I know usually when multiple classes are needed to select different classes we use , and I searched around too to make sure I did n't remember wrong but somehow if I use , there 's no error but it would n't detect the second select only detect the first . If I call the classes separately then the code would work though... | if ( ( $ ( '.use-remaining ' ) .prop ( `` checked '' ) ) || ( ( $ ( '.use-briquettes ' ) .prop ( `` checked '' ) ) ) ) { } if ( ( $ ( '.use-remaining , .use-briquettes ' ) .prop ( `` checked '' ) ) ) { } | Why I ca n't flip the check property using prop ( ) with a multiple selector ? |
JS | I am learning about Javascript prototypes and made a Fiddle ( http : //jsfiddle.net/3MuZa/1/ ) with this javascript : Interestingly , console.debug ( dog.__proto__ ) ; reveals that makeSound is a method of the prototype of the Animal class.However , I add that method to the prototype in a later line . Why is Console n... | function Animal ( name , sound ) { this.name = name ; this.sound = sound ; } var dog = new Animal ( `` Dog '' , `` Bark '' ) ; console.debug ( dog.__proto__ ) ; Animal.prototype.makeSound = function ( ) { console.log ( this.sound ) ; } ; | Why is console noting that I changed my prototype before I do ? |
JS | When user type wrong input than the custom error will generate and show error ( you have typed wrong input ) ..I have create default error but not custom error.I need . I need custom error.Anyone help me | var Scrn = document.querySelector ( ' # screen ' ) ; var maibox = document.querySelector ( '.calBox ' ) ; var exp = `` ; var errro_btn = document.querySelector ( ' # error_screen ' ) ; var close = document.querySelector ( ' # close ' ) maibox.addEventListener ( 'click ' , ( e ) = > { let vlu = e.target.value ; if ( vlu... | How will I throw error in calculator using javascript ? custom error not default errors ? using exceptional handling |
JS | slice ( ) is not working properly . I want to display 4-4 divs . It 's working but not all divs are being displayed . Right now I have 30 box divs but when I scroll down its just display 24 divs , why ? I want to display all divs . | $ ( window ) .scroll ( function ( ) { var position = $ ( window ) .scrollTop ( ) ; var bottom = $ ( document ) .height ( ) - $ ( window ) .height ( ) ; if ( position == bottom ) { var row = Number ( $ ( ' # row ' ) .val ( ) ) ; var allcount = Number ( $ ( ' # all ' ) .val ( ) ) ; var rowperpage = 3 ; row = row + rowper... | slice ( ) is not working properly with jQuery ? |
JS | Let 's look at the examples below : Q1 : Why is the output 0 here ? What does it mean ? Q2 : When typeof a and typeof 7 both are number , why a.constructor ( ) runs whereas 7.constructor ( ) does n't ? | var a = 7 ; console.log ( a.constructor ( ) ) ; // prints 0 ( Why ? ) var a = 7 ; var bool = typeof a === typeof 7 ; console.log ( a.constructor ( ) ) ; // 0console.log ( ( ++a ) .constructor ( ) ) ; // 0console.log ( 7.constructor ( ) ) ; // SyntaxError : Invalid or unexpected tokenconsole.log ( ++a.constructor ( ) ) ... | Why is the output 0 here . var a = 7 ; a.constructor ( ) ; |
JS | So here i am having a div created using normal HTML like this.And by using jquery selector i am inserting html elements dynamically likeHere i am expecting the output like this.But the original output is I cant understand why it is coming like this . Correct me if i asked anything wrong . Thanks in advance | < div id= '' prop '' > < /div > var Container = $ ( ' # prop ' ) ; Container.html ( ' < p > Hello World < /p > ' ) ; Container.append ( ' < p > This is awesome < /p > ' ) ; Container.html ( ' < p > Hello World < /p > ' ) ; Container.append ( ' < p > This is awesome < /p > ' ) ; Hello WorldThis is awesomeThis is awesome... | Unexpected behaviour of jQuery html ( ) and append ( ) |
JS | I have an issue : thre is a list of users , and I want to add appointment to any user , so on user screen a PlusButton sending user on the add appointment screen ( the PlusButton rendered from headerRight of the user screen ) . BUT I dont know how to pass to AddAppointmentScreen users id , because link to screen not vi... | const HeaderRight = ( { navigation , target } ) = > { return ( < Button transparent onPress= { ( ) = > navigation.navigate ( target ) } > < Icon name='plus ' type='Entypo ' style= { { fontSize : 26 } } / > < /Button > ) } < Stack.Screen name='Patient ' component= { PatientScreen } options= { { title : 'Карта пациента '... | How to pass params from one screen to another via reactnavigation v5 |
JS | I stuggle a lot with data I get from an API : This is the way the data gets returned , the amout of arrays differs.This is the way it SHOULD lookThis gives me the desired result , but it is not dymanic , since I have to provide the names of the arrays , and the amount of arrays in the object is not allowed to change.Ca... | const objData = { arr1 : [ 1,2,3 ] , arr2 : [ 1,2,1 ] , arr3 : [ 2,1,2 ] , arr4 : [ `` a '' , '' b '' , `` c '' ] } const desired = [ { a : 1 , b : 1 , c : 2 , d : `` a '' } , { a : 2 , b : 2 , c : 1 , d : `` b '' } , { a : 2 , b : 1 , c : 2 , d : `` c '' } ] const DataObj = [ ] for ( let i = 0 ; i < objData.arr1.lengt... | Convert object with multiple arrays to array of objects |
JS | I think console.log ( args ) ; should output 'John ' , but when I run this code , the output is [ [ Function ] ] So I am confused . | 'use strict ' ; Promise.resolve ( ( ) = > 'John ' ) .then ( ( args ) = > { console.log ( args ) ; throw new Error ( 'ops ' ) } ) .catch ( ( ex ) = > { console.log ( ex ) } ) .then ( ( ) = > { throw new Error ( 'ups ' ) console.log ( 'Doe ' ) } ) | How to understand this Promise code ? |
JS | I have set of three times in the format of Minute : Seconds : Miliseconds which I need to add to together and get the total time..for example the one I have used is : 0:31.110 + 0:50.490 + 0:32.797 which = 1:54.397so how to do this in javascript ? Here is JS CodeI do n't know where to begin but I have just come up with... | var sp1 = $ ( ' # table tr td : nth-child ( 2 ) ' ) .text ( ) var sp2 = $ ( ' # table tr td : nth-child ( 3 ) ' ) .text ( ) var sp3 = $ ( ' # table tr td : nth-child ( 4 ) ' ) .text ( ) var1 = sp1 + sp2 + sp3 $ ( 'td : nth-child ( 5 ) ' ) .html ( var1 ) ; | Add rows values of a time |
JS | I 've something like : In a result I want something like : How can I achieve this using jQuery ? Please help me on that . | < div class= '' the_notice '' > < span class= '' time '' > | 3:48pm < /span > To < strong > 2013-03-16_10-56-33 < /strong > By < strong > XYX < /strong > < /div > < div class= '' the_notice '' > < span class= '' time '' > | 3:48pm < /span > < div class= '' wrap '' > To < strong > 2013-03-16_10-56-33 < /strong > By < st... | Wrapping some part of html using jQuery |
JS | I have multiple toggles being called at the same time during a click /eventListener and it works but I 'm wondering if there is a cleaner way to write the code where it does n't look so repetitive.Here is a snippet of the code I 'm trying to refactor/clean up . Any help or point in the right direction is greatly apprec... | document.getElementById ( `` menu-toggle '' ) .addEventListener ( `` click '' , mobileMenuToggle ) ; function mobileMenuToggle ( ) { var hideMenu = document.getElementById ( `` mobile-menu-container '' ) ; hideMenu.classList.toggle ( `` hide-menu '' ) ; var hideMenuIcon = document.getElementById ( `` menu-toggle '' ) ;... | Is there a cleaner way to call multiple toggles & elements during a click event listener with vanilla JavaScript ? |
JS | So , I have an image in the middle of the page ( where I want it to remain ) and while I hold the LMB I want it to get a little bit smaller , then go back to its previous size when released.Below the code : I tried get that target using jQuery ( but the position of the image changes and it is not centred anymore ) .Tha... | $ ( document ) .ready ( function ( ) { $ ( `` # banana '' ) .mousedown ( function ( ) { $ ( `` # banana '' ) .css ( `` height '' , '' 70 % '' ) ; } ) ; $ ( `` # banana '' ) .mouseup ( function ( ) { $ ( `` # banana '' ) .css ( `` height '' , '' 100 % '' ) ; } ) ; } ) ; .centered { text-align : center ; display : block ... | How to make image/div smaller when LMB is being pressed ? |
JS | I am a newbie in js and jquery and need help with rewriting my code from jquery to pure js.I 've got several parent divs . Each of them have a child div inside.I want to add a class to both child and parent , but to parent as an attribute value in data-name . Class names are stored in an array , in other words first pa... | $ ( `` .back '' ) .each ( function ( i ) { $ ( this ) .addClass ( tile_array [ i ] ) ; $ ( this ) .parent ( ) .attr ( `` data-name '' , tile_array [ i ] ) ; } ) ; var backs = document.querySelectorAll ( 'back ' ) ; for ( let i = 0 ; i < backs.length ; i++ ) { for ( let j = 0 ; j < tile_array.length ; j++ ) { backs [ i ... | .each ( ) add an attribute to a parent from jquery to js |
JS | Is there a difference between how JavaScript handles the following two declarations ? JavaScript seems to treat them the same . If they really are the same then , is there a `` correct '' or preferred way to declare this ? | var foo = { foo : true , bar : 1 } ; var foo2 = { `` foo '' : true , `` bar '' : 1 } ; | Object literal notation differences in JS |
JS | My understanding of a constructor is a function is used to build up the object.Would this catRecord function count as a constructor ? | function catRecord ( name , birthdate , mother ) { return { name : name , birth : birthdate , mother : mother } ; } | Is this function similar to a constructor ? |
JS | I am building a JavaScript game , based on Mario . I have already implemented `` physics '' for lava , so when the character would fall into it , they would lose 1 life . What I am trying to achieve is that lava drops would act the same , so on contact they would hurt the character and make it respawn at the start of t... | ////////////////////////////// // This is only a demo code // //////////////////////////////var LEVELS = [ [ `` `` , `` `` , `` `` , `` `` , `` xxx `` , `` xx ! xx `` , `` x ! ! ! x `` , `` xx ! xx `` , `` x xvx `` , `` x x '' , `` x x '' , `` x x '' , `` x x '' , `` x x '' , `` x @ xxxxx o x '' , `` xxxxxx xxxxxxxxx x... | How do I make lava drops damage the character ? |
JS | I 'm trying to create a custom scroller , and I 'm using translate3d to scroll . The only problem is , when you scroll all the way to the bottom , the thumb ( scroller ) goes too far down . I 'm using the accepted formula , but for some reason , it goes past its parent wrapper . Here 's the formula : What am I doing wr... | scrollPosition * scrollBarThumb_height / content_height console.clear ( ) ; var innerWrapper = document.getElementById ( 'innerWrapper ' ) ; var scrollBar = document.getElementById ( 'scrollbar ' ) ; var scrollBarThumb = scrollBar.firstElementChildscrollBarThumb.style.height = ( innerWrapper.offsetHeight * innerWrapper... | Div goes past its parent element |
JS | I have seen this a few times in a few node examples but am never quite sure what to make of it . One example is with a net.Socket . Here is a socket after a warning has been emitted from data listeners.Another example is in using /^ ( some ) ( regex ) $ /.exec ( `` someregex '' ) I 'm not sure I understand what this da... | > commands._events.data [ [ Function ] , warned : true ] ; [ 'someregex ' , 'some ' , 'regex ' , index : 0 , input : 'someregex ' ] | What is this data structure that appears as a list , but has key value pairs ? |
JS | We found unexpected behavior with URL object in safari . When you convert URL to string it will add 0 port ( :0 ) if you set the port property to an empty string . e.g.From spec I see : If the given value is the empty string , then set context object ’ s URL 's port to null.So is it bug or feature in safari ? | let url = new URL ( 'https : //www.example.com ' ) ; url.port = `` ; console.log ( url.toString ( ) ) ; // expected `` https : //www.example.com/ '' , actual `` https : //www.example.com:0/ '' | Safari convert `` ( empty string ) to 0 in URL |
JS | I 've a page with two input fields . I 've a JS object ( info ) containing 'reference ' and a 'value ' field of each item . For each item , there 's a corresponding 'input ' field with matched by 'class ' attribute . When a user updates a matching input field , I want to add it 's 'value ' in the info object.The proble... | $ ( document ) .ready ( function ( ) { var info = { name : { ref : `` a2350 '' , value : `` '' } , location : { ref : `` a2351 '' , value : `` '' } } ; for ( var p in info ) { if ( info.hasOwnProperty ( p ) ) { $ ( 'input . ' + p ) .focusout ( function ( ) { var val = $ ( this ) .val ( ) ; info [ p ] .value = val ; // ... | How can I dynamically get matching inputs fields to add values to an object in Javascript ? |
JS | Displaying values in lakhs , crores instead of millions.I am using this function to format numbers , but how to use this in chart ? | function formatIndianSuffix ( num ) { var x = parseInt ( num ) .toString ( ) ; var len = x.length ; var formattedNum = `` '' ; if ( len < = 3 ) { formattedNum = '₹ ' + Math.floor ( x ) ; } else if ( len > 3 & & len < 6 ) { formattedNum = '₹ ' + ( roundOff ( x / 1000 ) ) .toString ( ) + ' K ' } else if ( len > = 6 & & l... | Is it possible to display values in Indian System in ZingChart ? |
JS | I 'm using yeoman angular-fullstack to generate my project . So the client is angularJs ( typeScript ) and the backend is nodeJs . The problem is I got a variable and when I print it to the console , I get a very long string , ( if u need to know its a photo_reference from googleplacesapi ) .And when I pass it to the w... | for ( var photo of response.data.result.photos ) { this.getImages ( photo ) ; console.log ( photo.photo_reference ) ; } getImages ( photo_reference : string ) : void { this. $ http.get ( '/api/image/ ' + photo_reference ) .then ( ( response ) = > { } ) ; } export function show ( req , res ) { console.log ( `` photorefe... | String turned to Object when passed from client to nodeJS |
JS | Recently I discovered that this syntax works in JavaScript ( Chrome 53 ) : I see that param1 can be used as variable that references item with index 0 in the first argument ( declared as array ) .My questions are:1 ) How is this syntax named ( the [ param1 ] part that lets you use param1 as variable ) ? 2 ) Why does ``... | function foo ( [ param1 ] ) { // Function argument is declared as array and param1 is used as variable ? What is the name of this syntax ? console.log ( param1 ) ; } foo ( [ 'TestParameter1 ' ] ) ; // Case 1 - works . Output : TestParameter1foo ( 'TestParameter1 ' ) ; // Case 2 - works ? ? ? Why ? Output : TestParamete... | Named array element used in function definition |
JS | I 've been using a pattern in my node.js modules that seems so obvious to me that I assume there must be something wrong with it or I would see more people doing it . To keep private variables that are global to the module , I simply attach them as properties on the module object . Like so : This seems preferable to me... | module.exports = { init : function ( ) { module.someClient = initializeSomethingHere ( ) } , someMethod : function ( done ) { module.someClient.doSomething ( done ) } } var someClient ; module.exports = { init : function ( ) { someClient = initializeSomethingHere ( ) } , someMethod : function ( done ) { someClient.doSo... | use ` module ` as namespace |
JS | This ES6 code : Transpiled to : Gives error : The problem is this line : Because the argument name is same as its default parameter.This works : Is this a bug in Babel or is this not allowed in the spec itself ? | const log = ( ) = > console.log ( 'hi ' ) ; const parent = ( log = log ) = > log ( ) ; parent ( ) ; var log = function log ( ) { return console.log ( 'hi ' ) ; } ; var parent = function parent ( ) { var log = arguments.length < = 0 || arguments [ 0 ] === undefined ? log : arguments [ 0 ] ; return log ( ) ; } ; parent (... | Using same argument name as its default parameter in ES6 |
JS | I am learning react and I am following the quick start guide , In the topic Lifting State Up I found the Calculator componentMy question is about this sentence this.setState ( { scale : ' c ' , temperature } ) here I am expecting this.setState ( { scale : ' c ' , temperature : temperature } ) .Is this temperature assig... | class Calculator extends React.Component { constructor ( props ) { super ( props ) ; ... this.state = { scale : ' c ' , temperature : `` } } handleCelsiusChange ( temperature ) { this.setState ( { scale : ' c ' , temperature } ) } handleFahrenheitChange ( temperature ) { this.setState ( { scale : ' f ' , temperature } ... | Creating Object with variable as a key and value |
JS | Hi I have an array of dom elements ( li ) as shown below : I have a click event , and am appending a class to the list . Means when I click if the li is not the activated li , then other li 's class will be appended with this extra class.Now what I need to achieve is , I need to add a new class to the items ( lis ) bef... | Array [ 4 ] 0 : li.ui-steps-item.ui-state-default1 : li.ui-steps-item.ui-state-highlight2 : li.ui-steps-item.ui-state-default.ui-state-disabled3 : li.ui-steps-item.ui-state-default.ui-state-disabled private _btnClick ( _btn : any , config : any ) : void { var nodesArray=Array.prototype.slice.call ( this._vcr.element.na... | Dynamic accessing of javascript array |
JS | JsFiddle I am trying to read an object stored in a JSON and then print it on my web page.I have provided a link to the code above.I am expecting the output to be a string `` HelloWorld '' which is underline.ps : I can not edit the JSONobj is the object that is being fetched , I could not share the JSON so i have used a... | < script > angular.module ( 'module ' , [ ] ) ; angular.module ( 'module ' ) .controller ( 'hello ' , function ( $ scope ) { $ scope.obj = { `` text '' : `` < u > HelloWorld < /u > '' } ; } ) ; < /script > < body > < div ng-app='module ' ng-controller='hello ' > Current : { { obj.text } } < br > < br > Expected : < u >... | How to parse the html which is embedded in a string inside a JavaScript object ? |
JS | I was wondering what states are kept between two lines of JavaScript code submitted to babel-node . My confusion arises because if you write two lines of code , you can override an variable definition without an error . For example , with babel-node -- presets es2015 , you can do : Now if you write it in one line , you... | > const a = 1 ; undefined > let a = 2 ; undefined > const a = 1 ; let a = 2 ; TypeError : repl : Duplicate declaration `` a '' ... | What state is kept between JavaScript lines ? |
JS | The value of ' a ' seems to lose global scope when the constructor a is called . | var a = 6 ; function b ( ) { a = 10 ; function a ( ) { } console.log ( a ) ; //10 } b ( ) ; console.log ( a ) ; //6 | JavaScript scope gets changed ? Why does this happen ? |
JS | Lets say we have defined this function in the global scope : In most examples explaining closures I see executing : from the global scope would just return the inner function : Now that makes total sense , because of this line in createCounter function declarationSo my question is , why does this : Finally get the func... | function createCounter ( ) { var counter = 0 ; function increment ( ) { counter = counter + 1 ; console.log ( `` Number of events : `` + counter ) ; } return increment ; } createCounter ( ) ; function increment ( ) { counter = counter + 1 ; console.log ( `` Number of events : `` + counter ) ; } return increment ; var c... | Final piece of javascript closures I stil do n't understand |
JS | Is there a proper/standard way ? vs | < a href= '' # '' onclick= '' function ( ) ; '' > Link < /a > < script > $ ( document ) .ready ( function ( ) { $ ( ' # link1 ' ) .click ( function ( ) { ... } ) ; } ) ; < /script > < a href= '' # '' id= '' link1 '' > Link < /a > | What are the benefits and/or pitfalls of calling a function directly from an anchor tag vs creating events onload ? |
JS | I have a list of items that I want to traverse through from any point in any direction . I also want to loop around the list , meaning if I end up on the last list item and click on next , I want the next item to be the first item on the list . My page is simple , just an unordered list of 5 items , 2 buttons ( one for... | $ ( function ( ) { var prev = $ ( `` # prev '' ) ; // grabbing the prev button var next = $ ( `` # next '' ) ; // grabbing the next button var listItems = $ ( `` # listItems p '' ) ; // grabbing the p elements of the list items var results = $ ( `` # results '' ) ; // grabbing the textarea var itemText ; // variable fo... | Traversing a list with jQuery |
JS | I have two divs which has one circle along with one smily where innercircle1 div is rotating with given animation.What i want is when i hover on innercircle1 div it should stop but with their current transform origin position , Currently when i hover over innercircle1 div it goes to their starting point i.e . their giv... | body { background : # 000 ; color : # fff ; } @ keyframes circle { from { transform : rotate ( 0deg ) ; } to { transform : rotate ( 360deg ) ; } } @ keyframes inner-circle { from { transform : rotate ( 0deg ) ; } to { transform : rotate ( -360deg ) ; } } .outercircle { border : 1px solid red ; border-radius : 50 % ; wi... | On hover stop animation at their respective position |
JS | I am trying to extract the keys of each object in the array , then i will collect all the keys , after that i concatenate the small chunk key arrays . Then i use set to eliminate duplicates and get all the keys.I am able to get the result . Is there any better approach for thisAny help appreciated | let data = [ { `` test1 '' : `` 123 '' , `` test2 '' : `` 12345 '' , `` test3 '' : `` 123456 '' } , { `` test1 '' : `` 123 '' , `` test2 '' : `` 12345 '' , `` test3 '' : `` 123456 '' } , { `` test1 '' : `` 123 '' , `` test2 '' : `` 12345 '' , `` test3 '' : `` 123456 '' } , { `` test1 '' : `` 123 '' , `` test2 '' : `` 1... | Collecting the keys from array of objects and reducing it into a single array and removing duplicates |
JS | I have following code . I have n't been able able to figure out why click event occurs even though I have n't set the function to onclick attribute of button . | var x = 0 ; var onclick = function ( ) { console.log ( `` x = `` + ++x ) ; } ; < button type= '' button '' onclick= '' '' > Click < /button > | function `` onclick '' is called even though it is not set in button |
JS | I am just curious about this.Let 's say I have an array of objects and I create 1 object , lets name the array of objects items and the object item.I want to get a particular item in my array of items by using the following code : The get_item ( ) basically gets an object matched with the supplied id.So my question is ... | //gets an item base on IDfunction get_item ( td ) { var item = undefined ; $ .each ( items , function ( i , val ) { if ( val.item_id == td ) { item = val ; } } ) ; return item ; } | Assigning a javascript object with and object inside an array |
JS | The following as you 'd expect does n't work : This works , though : Since functions and classes are objects , and in both cases I set a property for it , why is it that the results differ ? Where is it getting User reference ? | let User = { foo ( ) { User.prop = 1 ; } } ; let User2 = User ; User = null ; User2.foo ( ) ; // Can not set property of nullconsole.log ( User2.prop ) ; class User { static foo ( ) { User.prop = 1 ; } } let User2 = User ; User = null ; User2.foo ( ) ; console.log ( User2.prop ) ; // 1 | Why class name can be referenced inside class even after it was redefined ? |
JS | first time posting so I apologize if I miss something obvious here.What I am trying to do is pretty simple ... .in php . I can do it in my sleep . However , my page requires an integration of javascript , which I am not particularly skilled in yet.I have a question about a working portion of the script , that I would l... | $ ( `` # M1L1Box '' ) .click ( function ( ) { $ ( `` # M1L1BoxFeedback '' ) .text ( this.checked ? `` - completed '' : `` - mark as complete '' ) ; } ) ; $ ( `` # M1L2Box '' ) .click ( function ( ) { $ ( `` # M1L2BoxFeedback '' ) .text ( this.checked ? `` - completed '' : `` - mark as complete '' ) ; } ) ; $ ( `` # M1L... | Javascript equivalent to php for loop efficiency |
JS | I am trying to create an dynamic order form using Jquery and PHP and got stuck . I have a Jquery code that onclick adds a new set of fields . Also in that jquery code I apply some style and jquery to one of the fields . Its an Multiselect , Searchable dropdown list . Problem here however . I can apply this style so tha... | $ ( document ) .ready ( function ( ) { var max_fields = 100 ; //maximum input boxes allowed var wrapper = $ ( `` .input_fields_wrap '' ) ; //Fields wrapper var add_button = $ ( `` .add_field_button '' ) ; //Add button ID var x = 1 ; //initlal text box count //THIS WORKS ! ! var arrayFromPHP = [ 'foo ' , 'bar ' ] ; // <... | Jquery ID apply |
JS | Is there a way to write this logic without an if statement or in a succinct way ? | let notStudent , name , isRegistered if ( studentDetail & & studentDetail.fields ) { ( { notStudent , name , isRegistered } = studentDetail.fields ) } | How to destructure a nested object only when it has a value ? |
JS | I want to get the characters after @ symbol till a space character.for eg . if my string is like hello @ world . some gibberish. @ stackoverflow . Then I want to get the characters 'world ' and 'stackoverflow ' . Here is what I have been trying.I can get the occurences of @ and spaces and then trim that part to get my ... | var comment = 'hello @ world . some gibberish . @ stackoverflow ' ; var indices = [ ] ; for ( var i = 0 ; i < comment.length ; i++ ) { if ( comment [ i ] === `` @ '' ) { indices.push ( i ) ; for ( var j = 0 ; j < = i ; j++ ) { startIndex.push ( comment [ j ] ) ; } } } | String Matching Javascript |
JS | What is happening ... if you change the spacing or line breaks between different tags within the HTML , it causes problems for the JavaScript or CSS ( not really sure which one ) .The code itself is a basic collapsible list using only HTML , JavaScript , and CSS . I realize you can do this with jquery etc etc . Just tr... | < div class='collapsibleCont ' > < h3 id='collapsible1 ' class='collapsibleTitle ' onclick= '' handleCollapsible ( 'collapsible1 ' ) '' > + title < /h3 > < p style= '' display : none '' class='collapsibleContent ' > hello < /p > function handleCollapsible ( id ) { var clickedTitle = document.getElementById ( id ) ; var... | HTML space format affecting JavaScript/CSS |
JS | I have a set of rectangles of different sizes and I want to put them next to each other so there are as little gaps in there as possible : but for : andthis is what I get : Is there a way I could achieve that result with plain css ? I want to avoid css3 and javascript and I want the result to run on older browsers . If... | < div class= '' box '' > < div class= '' item item-001 '' > < /div > < div class= '' item item-003 '' > < /div > < div class= '' item item-005 '' > < /div > < div class= '' item item-002 '' > < /div > < div class= '' item item-004 '' > < /div > < div class= '' item item-001 '' > < /div > < div class= '' item item-001 '... | How can I put items of different sizes in one page avoiding too many gaps between them ? |
JS | I have a loop that looks like this : If I write at the top of the loop var TheThis = $ ( this ) ; and then replace $ ( this ) with TheThis is that a performance optimization or not really ? | $ ( ' # SomeSelectorID ' ) .find ( '.SomeElementsByClassName ' ) .each ( function ( ) { $ ( this ) .some code here ; $ ( this ) .some other code there ; $ ( this ) .some other code here and there ; } ) ; | Does replacing $ ( this ) with a variable make any performance difference |
JS | I have a problem I would like you guys to help me figure it out please.The form is now refreshing the same page without any result , but I 'd like it to paste the data from the php file.PS : this exact same code works on another project like a charm . | < script type= '' text/javascript '' src= '' js/jquery-1.4.2.min.js '' > < /script > < script type= '' text/javascript '' > $ ( document ) .ready ( function ( ) { $ ( `` # myform '' ) .validate ( { debug : false , rules : { } , messages : { } , submitHandler : function ( form ) { $ .post ( 'goCarnet.php ' , $ ( `` # my... | Sending form without refreshing |
JS | I working with datatables , and i try to make filtering possibility , and problem is that i want to chosse from checkboxes which column i need to filter.So in case if i chosse one column i result i got 4 or 5 column , but i chosse 1 , and i can find where the issues. [ ! [ enter image description here ] [ 1 ] ] [ 1 ] A... | addSpliting ( `` ) ; function addSpliting ( val ) { if ( val ! = `` ) { $ ( `` # test1 '' ) .DataTable ( { destroy : true , searchPanes : { layout : 'columns-4 ' , } , dom : 'Pfrtip ' , columnDefs : [ { searchPanes : { show : true , } , targets : val } ] } ) ; } else { $ ( `` # test1 '' ) .DataTable ( { destroy : true ... | How to set columns from checkboxes for filtering datatable jQuery |
JS | I am just playing with some basic Jquery and something strange is happening . I have two elements on the page.. an h1 heading , and a generic link . When I click the link I would like the text to change to `` This text has now changed '' , and it does , but then either the button disappears and a new h1 is created with... | < html > < head > < title > < /title > < link rel= '' stylesheet '' type= '' text/css '' href= '' css/main.css '' > < script src= '' https : //ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js '' > < /script > < script src= '' js/main.js '' > < /script > < /head > < body > < h1 > This element should change. < h... | All of the elements change on Click , not just the targeted one |
JS | Thinking of a better way of doing this - I have these arrays available : and in my code where I use them I do : for each model to declare them to use later.What would be a better way to do in a for loop , so I simply pass the model array name , split the array into an index , so if new models are added , they are actua... | var model1 = [ '10 ' , '20 ' , '30 ' , '40 ' , '50 ' , '60 ' ] ; var model2 = [ '80 ' , '100 ' , '200 ' , '300 ' , '400 ' , '500 ' ] ; var model3 = [ ' 1 ' , ' 2 ' , ' 3 ' , ' 4 ' , ' 5 ' , ' 6 ' ] ; $ scope.sli [ 'model1 ' ] [ 0 ] =0 ; $ scope.sli [ 'model1 ' ] [ 1 ] =10 ; $ scope.sli [ 'model1 ' ] [ 2 ] =20 ; $ scope... | split multiple arrays into variables based on name |
JS | I 've designed this regex with several online tools and with help of the community : https : //regex101.com/r/hJ4pD5/1The goal is to extract all alternatives to a question . According to regexr and regex101 this is a valid Javascript regex which works well with the test data ( pastebin ) : Expected matches should be : ... | ( \s [ A-Z ] \. ) .+ ? ( ? = ( \s [ A-Z ] \. ) | ( \W ? ( Answer : ) \W ? ) ) 1 . Question goes here : A . Answer oneB . Answer two C. Answer three D. Not indented AnswerAnswer : B is correct /** * Created by Schwusch on 01/08/2016 . */ $ ( document ) .ready ( start ) ; var questionsRaw ; var questionsFormatted = [ ] ;... | Valid RegEx according to online test tools , not getting any matches when reading file in browser |
JS | In Scala , view allows preventing creating an entirely new collection.e.g . In Scala , what does `` view '' do ? Is there something similar in JavaScript ? My use case : As you can see in the above code , 2 intermediate collections would be created . Is there some way in JavaScript to avoid creating the above intermedi... | x = inputValue.split ( `` , '' ) .map ( x = > x.trim ( ) ) .filter ( f1 ) .map ( f2 ) | Equivalent of Scala View in JavaScript |
JS | I have below code and i want to get the values entered in user name and password textbox and send them to node js service . But I dont know how to do that . Things is that nothing is working . I can only render the page but functions are not working and not able to get the values as well from the textbox . I am very mu... | import { FormGroup } from `` react-bootstrap '' ; import `` ./Login.css '' import `` bootstrap/dist/css/bootstrap.min.css '' class LoginClassComponent extends React.Component { constructor ( props ) { super ( props ) ; console.log ( props ) ; this.state = { username : `` , password : `` } this.handleTextChange = this.h... | How will I get a textboxes values in react js |
JS | I have the following : I have the following jqueryThe value of the variable is always a single whole number but will not always be 3 : I have tried this numerous ways and can not get the value to change . My latest attempt was : My end result , is to subtract 1 from whatever the current value of `` lable-info '' is , a... | < span class= '' label-info '' > 3 < /span > var replaceit = $ ( this ) .closest ( ' : has ( .label-info ) ' ) .find ( '.label-info ' ) .text ( ) ; ie : 1 , 2 , 3 , 4 , 5. return $ ( this ) .closest ( ' : has ( .label-info ) ' ) .html ( ) .replace ( replaceit , ( replaceit - 1 ) ) ; < span class= '' label-info '' > 2 <... | Changing values with jQuery |
JS | I got undefiend , I do n't know why . I 've tried not to parse html use string to search my id , which is all-tickets , it does n't work too . Any thought ? I also tried $ ( data ) .find ( ' # all-tickets ' ) .parent ( ) ; , does n't work : ( | var data = $ .parseHTML ( data.responseText ) ; console.log ( data ) // above img is the result of thisvar elem = $ ( data ) .find ( ' # all-tickets ' ) .get ( 0 ) ; console.log ( elem ) | get ( ) jquery got undefined in my case |
JS | I have a predefined function that I want to fire when two different events happen . The below code works fine , but is there a way to combine these to make the code more efficient ? | $ ( `` select [ name=some_selector ] '' ) .blur ( function ( ) { predefined_function ( ) ; } ) ; $ ( `` a # some_link '' ) .click ( function ( ) { predefined_function ( ) ; } ) ; | Efficiently writing functions |
JS | i have this script for a Whack a mole game , but i ca n't seem to make my div 's pop up when I want them to by using a random number generator . This is my code : ( by the way this is my first game I have ever made so it 's pobably a stupid question : ) ) and my html that 's relevant : I have not started working on my ... | //minigamesetInterval ( function ( ) { var randomnumber = 1 + Math.floor ( Math.random ( ) * 10 ) ; if ( randomnumber = `` 1 '' ) { $ ( ' # mole1 ' ) .show ( ) ; } ; if ( randomnumber = ' 2 ' ) { $ ( ' # mole1 ' ) .show ( ) ; } ; if ( randomnumber = ' 3 ' ) { $ ( ' # mole1 ' ) .show ( ) .delay ( 300 ) .hide ( ) ; } ; i... | How do is use the SetInterval function and the 'if ' to make div 's pop up ? |
JS | How can I add/remove a row with validation ? Here is my working example . Iwant to set only validation .http : //jsfiddle.net/Bhuro/o6g60b57/1/ | < div id= '' mainDiv '' > < div class= '' one '' > < div class= '' row '' > < div class= '' input-field col s1 '' > < input type= '' text '' class= '' sno '' name= '' sno [ ] '' value= '' 1 '' readonly > < label for= '' Sr '' > Sr < /label > < /div > < div class= '' input-field col s2 '' > < input id= '' item_code '' t... | How Can I Add/Remove a row with validation |
JS | I have this function from : https : //rosettacode.org/wiki/Combinations # ES6In my environementt console.log ( show ( comb ( 3,15 ) ) ) ; ( same as this snippet bellow ) take aprox . 4 seconds to processIf I try console.log ( show ( comb ( 3,16 ) ) ) ; that take aprox . 16 secondsIf I try console.log ( show ( comb ( 3,... | ( ( ) = > { 'use strict ' ; // COMBINATIONS -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - // comb : : Int - > Int - > [ [ Int ] ] const comb = ( m , n ) = > combinations ( m , enumFromTo ( 0 , n - 1 ) ) ; // combinations : : Int - > [ a ] - > [ [ a ] ] const combinations = ( k... | calculate time to process combinations javascript |
JS | The output is from 0 to 53075 in Internet explorer while it is 12561 in Chrome.I do n't understand why different browsers display different outputs and how it stops the recursion.Thank You . | < html > < head > < title > Frontpage < /title > < /head > < h3 > Hello < /h3 > < script > var a=1 ; function myFunc ( ) { document.write ( a+ '' `` ) ; a=a+1 ; myFunc ( ) ; } < /script > < body > < button type= '' button '' onclick= '' myFunc ( ) '' > Hey there < /button > < /body > < /html > | Why do different net browsers display different output for this piece of code ? |
JS | I have code that allows me to drag and drop to rearrange items and move them from container to container , but I also want to update the number inside the span tag to match it 's position in order.For example , `` Colorado '' is in the 0 position , but when I drag it after `` Utah '' I want to update `` Montana '' to h... | const draggables = document.querySelectorAll ( '.draggable ' ) const containers = document.querySelectorAll ( '.container ' ) draggables.forEach ( draggable = > { draggable.addEventListener ( 'dragstart ' , ( ) = > { draggable.classList.add ( 'dragging ' ) } ) draggable.addEventListener ( 'dragend ' , ( ) = > { draggab... | Update the displayed number to match its position in the order of elements in pure javascript |
JS | consider I declare two variables like this ( done within REPL , with node v7.7.2 ) , which I expect to be arrays : then the following should work identically , but it does n't : in looking , it seems x and y are both identical : so why the difference ? | var x = Array ( 4 ) var y = Array.from ( { length : 4 } ) x.map ( Math.random ) [ , , , ] y.map ( Math.random ) [ 0.46597917021676816 , 0.3348459056304458 , 0.2913995519428412 , 0.8683430009997699 ] > typeof x'object ' > typeof y'object ' > Array.isArray ( x ) true > Array.isArray ( y ) true > x.length4 > y.length4 > t... | Manufacturing an array - why is it different ? |
JS | I 've been trying to wrap my head around javascript prototypal inheritance and while reading through John Resig 's book `` Pro Javascript Techniques '' , I was trying things like this : However , I also tried other functions that should work on a number , like toFixed ( ) toPrecision ( ) and even toString ( ) but nothi... | alert ( `` me '' .constructor ) ; //Correctly return Stringalert ( alert.constructor ) ; //Correctly return Function alert ( 55.constructor ) ; //I was expecting Number , but it returns error `` SyntaxError : identifier starts immediately after numeric literal '' in FF and in IE , it says it is expecting `` ) '' | calling constructor on a number in javascript |
JS | Why ca n't you append to an element that you use to wrap another - see example below ? | var $ test = $ ( '.test ' ) , $ test1 = $ ( '.test1 ' ) , $ move = $ ( '.move ' ) , $ testWrapper = $ ( ' < div class= '' test-wrapper '' > < /div > ' ) , $ test1Wrapper = $ ( ' < div class= '' test1-wrapper '' > < /div > ' ) ; $ test.wrap ( $ testWrapper ) ; // move item and return to wrapper $ move.append ( $ test ) ... | ca n't append to jQuery wrap |
JS | I have seen several times in a project that I 'm working that before setting an element 's innerHtml the value is cleaned before , like this : I ca n't find any good reason to do this , just that everyone in the team follows this `` practice '' . From what I understand , anyone can redefine the innerHtml property to do... | var foo = document.getElementById ( 'foo ' ) foo.innerHTML = `` ; foo.innerHTML = ' < span > Bar < /span > ' | Should be an element `` cleaned '' before setting innerHtml ? |
JS | I hope you are great ! May someone shed a light on this oneUse casePage A opens page B with window.open ( ) Refresh page A and try to focus page B with window.open ( ) again.CodeProblemThe focus on page B happens but the page is reloaded . Is there any method to overcome this issue ? I want the page B to be focused wit... | if ( ! window.memwin || window.memwin.closed ) { window.memwin = window.open ( URL , `` windowName '' , `` '' , true ) } window.memwin.focus ( ) ; | Prevent window.open ( ) from refreshing the window |
JS | I have more than 10 buttons in a single page , so I need to write code at only once for hovering . and because of this I am using jQuery . Please go through my code.It works fine with a single hover , if we continuously hover on a button means it changes the color so if is there any other way to avoid this ? ? The colo... | $ ( document ) .ready ( function ( ) { $ ( '.button ' ) .hover ( function ( ) { var bc= $ ( this ) .css ( 'background-color ' ) ; var cl= $ ( this ) .css ( 'color ' ) ; $ ( this ) .css ( 'background-color ' , cl ) ; $ ( this ) .css ( 'color ' , bc ) ; } ) ; } ) ; .button { color : # FFFFFF ; text-align : center ; font-... | Is CSS hover effect transition changes the color ? |
JS | I have a parsed Json string that i would like to further split into 4 different arrays . I have tried using $ .parseJson ( ' [ ' + data + ' ] ' ) ; which returns all of the data into a single array . More Precisely i need it to look more like catData = [ Object , Object , Object , Object ] Thanks for your help.my data ... | [ { \ '' LkpMasterID\ '' :491 , \ '' LkpMasterCode\ '' : \ '' CAT INSURANCE\ '' , \ '' LkpMasterDescription\ '' : \ '' 25\ '' , \ '' Attribute\ '' : \ '' Cat Values\ '' , \ '' Dependency\ '' : null , \ '' LkpName\ '' : \ '' CAT INSURANCE\ '' , \ '' IsAttribute\ '' : false , \ '' IsActive\ '' : true , \ '' CreatedBy\ ''... | Create 4 arrays from parsed JSON string |
JS | I 'm reading JavaScript - The Good Parts currently . So I 've dealing with augmentation of types . I understand the motivation and the implementation . But if I look at the code ... ... then I do n't understand the purpose of the return.I have put the return in comments . That does n't have an effect . It functioned an... | Function.prototype.method = function ( ident , funct ) { this.prototype [ ident ] = funct ; return this ; // No idea . For what ? } ; Function.prototype.method = function ( ident , funct ) { this.prototype [ ident ] = funct ; return this ; } ; Date.method ( 'sayHello ' , function ( ) { alert ( new Date ( ) .toString ( ... | JavaScript : Augmenting types - Purpose of `` return this '' |
JS | Why are these 2 conditionals different : Incorrect : Because of this , you must test typeof ( ) first : Correct : I pulled this off the w3schools site . According to w3schools you must test the typeof ( ) first , why would this make a difference . The conditions look to be the same | if ( myObj ! == null & & typeof myObj ! == `` undefined '' ) if ( typeof myObj ! == `` undefined '' & & myObj ! == null ) | How are these conditionals any different ? |
JS | I have a grid at which I place an object I want to rotate right around a fixed cell ( cell3 ) . The object contains coordinates , like : Output : I want to rotate this object around cell3 e.g . using x : 2 , y : 2 without hard coding each cell position using some kind of ( basic ) trigonometry . I realize that I have t... | activeObject = { coords : { cell1 : { x : 0 , y : 0 } , cell2 : { x : 1 , y : 1 } , cell3 : { x : 2 , y : 2 } , cell4 : { x : 2 , y : 3 } , cell5 : { x : 3 , y : 3 } , } } activeObject = { coords : { cell1 : { x : 4 , y : 0 } , cell2 : { x : 4 , y : 1 } , cell3 : { x : 2 , y : 2 } , cell4 : { x : 1 , y : 2 } , cell5 : ... | How to rotate object depending on center cell |
JS | I am currently learning on how javascript is actually running in the machine and this is a piece of code I see in the example . I got no idea why the final alert is 1 instead of 10 . So I am wondering could any one help me explain how the javascript virtual machine is actually execute these code . Thanks ! | var foo=1 ; function bar ( ) { foo=10 ; return ; function foo ( ) { } } bar ( ) ; alert ( foo ) ; | A better understanding of javascript precompile |
JS | I 'm looking at Addy Osmani 's gist for a publication/subscription pattern here : https : //github.com/addyosmani/pubsubz/blob/master/pubsubz.jsHe surfaces his object as a global like this : What is the value of creating that getPubSubz function ? Would n't it be more straightforward to simply write : | ; ( function ( window , doc , undef ) { var topics = { } , subUid = -1 , pubsubz = { } ; ... .getPubSubz = function ( ) { return pubsubz ; } ; window.pubsubz = getPubSubz ( ) ; window.pubsubz = pubsubz ; | Creating a global variable from a function 's return value |
JS | I have two links at index.html to target.html.first link is simple . it 's just goes to target.html.but I want to do something else with the second link.simply:1-user clicks the second link to target.html2-not only target.html appears but also show-this-page-in-target.html-if-user-clicks-the-second-link.html appears in... | < a href= '' # '' id= '' load '' class= '' btn btn-primary '' > Load < /a > < script type= '' text/javascript '' > $ ( ' # load ' ) .click ( function ( ) { $ ( '.page-class ' ) .load ( 'show-this-page-in-target.html-if-user-clicks-the-second-link.html .target-class ' ) } ) ; < /script > | How to apply jQuery 's load ( ) function on page if I go to page via specific link |
JS | Here is what I was attempting with my code : Click an element that has the selection ( ) function.Function sets that element 's width.Function selects previously click item ( that also has selection ( ) function ) Function changes previous element 's widthHere is my JavaScript : Here is the relevant HTML : Currently , ... | var lastOne ; function selection ( event ) { event.target.style.width = `` 50px '' ; lastOne.style.width = `` 10px '' ; current = event.target.id ; lastOne = document.getElementById ( current ) ; } < img src= '' images/Star.png '' id= '' pic1 '' onclick= '' selection ( event ) '' > < img src= '' images/Star.png '' id= ... | Javascript issue managing variables |
JS | I want to add some CSS class toHow can I make this with jQuery or JavaScript | < table > < tr > < td > < a href src= '' xxx '' title= '' Some text '' > Link < /a > < /td > < td > < a href src= '' xxx '' title= '' '' > Link < /a > < /td > < /tr > < tr > < td > < a href src= '' xxx '' title= '' Some text '' > Link < /a > < /td > < td > < a href src= '' xxx '' title= '' Some text '' > Link < /a > < ... | Add CSS class to only those links that do not have 'title ' attribute |
JS | When binding a function to the same context , the resulting reference is different every time.Does that code copy the function every time ? Would n't there be any benefit in caching that behavior ? Is it implementation specific ? Or is it specified somewhere in ecmascript specification ? | function foobar ( ) { return 1 ; } var foo = foobar.bind ( this ) ; var bar = foobar.bind ( this ) ; console.log ( foo === bar ) ; // Nope | Why two bindings to the same function return different values |
JS | So I 've been working on a script that spawns bubbles at the mouse coordinates . It is a very basic script that calculates some things like a random opacity , random size , etc . Now , for some reason , some of the bubbles are n't placed at the right coordinates . The script is supposed to literally take e.offsetX and ... | var transform = ( function ( ) { // This piece is to test whether transform should be prefixed or not var testEl = document.createElement ( 'div ' ) if ( testEl.style.transform == null ) { var vendors = [ 'Webkit ' , 'Moz ' , 'ms ' ] for ( var vendor in vendors ) { if ( testEl.style [ vendors [ vendor ] + 'Transform ' ... | My script changes some values with what seems to be no reason |
JS | I am using this simple code to make a javascript visualizer for sorting algorithm but the problem is that it is very choppy and skips multiples frames while running even at a delay of 100ms . I have an i7 7700hq and gtx 1060 so I know that the problem is mostly not my laptop but my approach to it so what approach shoul... | k = [ ] len = 100 ; time = truecont = document.getElementsByClassName ( `` cont '' ) [ 0 ] ; cont.innerHTML = `` '' ; for ( let i = 0 ; i < len ; i++ ) { t = Math.round ( Math.random ( ) * 800 ) + 5 k.push ( t ) ; cont.innerHTML += `` < div class='block ' style = 'height : '' + t + `` px ' > < /div > '' } function rese... | Java Script Sorting algorithm visualizer |
JS | i have this working code bellow and i think he is a little bit too long and redundant can i customize it ? | $ ( `` # unique '' ) .click ( function ( ) { if ( $ ( this ) .is ( ' : checked ' ) ) { $ ( `` .lotud '' ) .show ( ) ; $ ( `` # add_lot '' ) .hide ( ) ; $ ( `` # lots_rows_contnr '' ) .hide ( ) ; $ ( `` .lotud input '' ) .prop ( { disabled : false } ) $ ( `` # lots_rows_contnr input '' ) .prop ( { disabled : true } ) } ... | Customize redundant Checkbox input Jquery Code |
JS | I am building an App on react native in which I want to be position something from rightwith following styles With That I was expecting To be on the absolute right side of the screen Here is how it is looking now | < View style= { searchDrop } > < TextInput style= { textInput } placeholder= '' Search Coin '' onChangeText= { ( text ) = > this.onSearch ( text ) } / > < TouchableOpacity onPress= { ( ) = > this.props.navigation.navigate ( `` CurrencySelection '' ) } > < Text style= { money } > < Icons name= '' money '' size= { 35 } c... | Positioning something from the right |
JS | I am trying to learn angular , and I have an example code snippet that is the following : Which works fine , but I want to fetch data from an API and then load the data into the $ scope.contents . I have tried the following : and this works , I am able to loop through the object of data returned from my API , however I... | $ scope.contents = [ { name : 'Chris Doe ' , abbreviation : 'Developer ' , } , { name : 'Ann Doe ' , abbreviation : 'Commerce ' , } , { name : 'Mark Ronson ' , abbreviation : 'Designer ' , } , { name : 'Eric Doe ' , abbreviation : 'Human Resources ' , } , { name : 'John Doe ' , abbreviation : 'Commerce ' , } , { name :... | How can I dynamically add values to a javascript object |
JS | I 'm reviewing ECMAScript 5.1 Specification kinda seriously.And I 'm curious if there is a way to tell what the `` real constructor function '' of an object in ES5 . ( not the explicit `` constructor '' property ) According to the spec , explicit `` constructor '' property is just a initial back-reference from the bypr... | function Foo ( name ) { this.name = name ; } var foo = new Foo ( `` Brian '' ) ; var bar = { a : 10 , b : function ( ) { if ( this.name ) return this.name ; } } ; Foo.prototype = bar ; var foo2 = new Foo ( `` John '' ) ; // Let me call Foo as `` real constructor '' of foo2 Object.getPrototypeOf ( foo2 ) === bar // true... | Is there no way to find the real constructor of an object in JavaScript |
JS | This is a fairly general question coming from a newbie in the learning phase and is on something I need clarifying.I 'm currently learning about objects and at this point I 'm learning about inheritance . At this point in the lesson I 've learned a few different ways to create objects but objects using the this keyword... | function Person ( ) { this.eyes = 2 ; this.ears = 2 ; this.arms = 2 ; this.hands = 2 ; this.feet = 2 ; this.legs = 2 ; this.species = `` Homo sapien '' ; } var person = new Object ( ) ; person.eyes = 2 ; person.ears = 2 ; person.arms = 2 ; person.hands = 2 ; person.feet = 2 ; person.legs = 2 ; person.species = `` Homo ... | Objects types in Javascript |
JS | This question is about the same names of function and variable.Please tell me -why this code does n't have errors : but this one wo n't work : Why it 's so ? | var Task = new Task ( ) ; function Task ( ) { console.log ( 'work ! ' ) ; } start ( ) ; function start ( ) { var Task = new Task ( ) ; } ; function Task ( ) { console.log ( 'work ! ' ) ; } | Variable name is like function name -- when causes error/when does n't |
JS | So I have an object that I need to sum a nested value for all the objects . My object looks likeI need to sum all the `` unit '' valuesI 've been trying to use .reduce for this but it only works when I have 2 items in my object , onces I get a 3rd I get an error.The rest of my code is the following : Not really sure wh... | const json = [ { `` other_sum '' : `` 1 '' , `` summary '' : { `` calculations '' : { `` time '' : 10 , `` unit '' : 25 } , `` updated '' : `` 2020-06-05 '' } } , { `` other_sum '' : `` 1 '' , `` summary '' : { `` calculations '' : { `` time '' : 20 , `` unit '' : 5 } , `` updated '' : `` 2020-06-05 '' } } , { `` other... | Trying to use .reduce on an object |
JS | I 've seen a code sample like that in some tutorial : And that it is equal to the following : I 'm a newbie , and never seen anything like this before . I ca n't really understand how the above can be the same ( without parameter on the renderSomething ( ) ) .I 've tried to recreate something similar to the above code ... | getSomething ( function onSomething ( name ) { return renderSomething ( name ) ; } ) ; getSomething ( renderSomething ) ; var name = 'alex ' ; console.log ( 'start ' ) ; function print ( cb ) { console.log ( ' a ' ) ; cb ( ) ; } function renderName ( name ) { console.log ( ' b ' ) ; console.log ( name ) ; } print ( fun... | Passing function as callback without argument - need help to understand it |
JS | Should the following code work ? Chrome 80 and Firefox 72 both throw a ReferenceError saying bar is not defined . So it seems like async function bar ( ) { ... } declarations are block scoped whereas function bar ( ) { ... } declarations are function scoped ? Confusing if that 's the case , but can someone just confirm... | if ( true ) { async function bar ( ) { console.log ( `` hello '' ) ; } } bar ( ) ; | ` function ` declarations are function scoped , but ` async function ` declarations are block scoped ? |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.