lang stringclasses 4
values | desc stringlengths 2 8.98k | code stringlengths 7 36.2k | title stringlengths 12 162 |
|---|---|---|---|
JS | I am at a bit of a loss for how how to do this.I have a web page . I want a user to scroll down , then at a specific distance from the top I want the mouse scroll to effect an elements position ( making it appear as thought that element is scrolling ) . then when that element hits a position ( ie top : -500 ) I want th... | //pageFeature.style.backgroundPosition = `` 0px `` + parseInt ( -y / 6 ) + 'px ' ) ; var element = document.getElementById ( 'container ' ) .getBoundingClientRect ( ) ; var elementTop = element.top //distance from top 720 ; // variable to stop function from being replayed on scroll when scrolling imagevar isScrollingIm... | scroll page then at certian position scroll element |
JS | In John Resig 's slideshow on how he was building jQuery 1.4 , he mentioned a point where he added an undefined variable to the jQuery closure because `` we can re-use ( the variable ) '' .undefined is not an ordinary variable : Therefore , we know that undefined is not a variable . So why would an undefined be re-unde... | > var undefined = 4 undefined > undefined undefined | Why does one reuse ` undefined ` ? |
JS | I 'm trying to have list elements on different lines . Using contenteditable , I am able to do so . However , when I reload the page , the content remains but without the separation between items . As a visual : ( Contenteditable ) Bones : Bones are coolBones are helpful ( After refreshing the page ) Bones : 1 . Bones ... | var app = angular.module ( `` TodoApp '' , [ `` LocalStorageModule '' ] ) ; app.controller ( `` TodoController '' , function ( $ scope , localStorageService ) { if ( ! localStorageService.get ( `` taskListActive '' ) ) { $ scope.tasksActive = [ { text : `` Do me next '' , priority : 1 , complete : false } , { text : ``... | Content Editable Loses Its Tab/ New Line on Refresh |
JS | I 'm writing an object hierarchy in JavaScript , I would like to call a method on an object 's parent when I 've shadowed that method in the object.E.g . : See the three lines at the bottom of the Sub.prototype.log function - is there a better way to do what I 'm trying to do there ? The second line is the best I 've b... | var Base = function Base ( msg ) { this.msg = msg ; } Base.prototype.log = function ( ) { console.log ( `` base log : `` + this.msg ) ; } var Sub = function Sub ( msg ) { Base.call ( this , msg ) ; } Sub.prototype = Object.create ( Base.prototype ) ; Sub.prototype.log = function ( ) { console.log ( `` sub log '' ) ; th... | Simpler / better way to call shadowed prototype method ? |
JS | I 'm writing a jQuery plugin , and I was wondering how to make sure that I do n't ever overwrite a future jQuery native method.For example , my plugin is called Foo and usage is $ ( 'selector ' ) .foo ( ) .jQuery 2.6 has noticed the popularity of Foo and decided that it will include it in the core package . It too is u... | ( function ( $ ) { // If jQuery adds this method , we do n't want to overwrite it if ( typeof $ .foo === 'function ' ) { return ; } ; $ .fn.foo = function ( ) { // Foo } ; } ) ( jQuery ) ; | What is the best way to make sure a jQuery plugin wo n't ever overwrite a jQuery native method ? |
JS | I 'm trying to filter a list of elements by their index , and it is possible that the first item is the item I want to get . It seems that trying to filter a 0 using does not work . Though Number.isInteger ( 0 ) is true.Here 's a fiddle I 've created to show an example . The array filtered should have two values , not ... | arr.filter ( function ( f ) { if ( Number.isInteger ( f ) ) return f ; } ) ; | Filter an array of numbers where 0 is a valid input |
JS | I want to give genetic algorithms a chance but I ca n't seem to find a solution for this problem.This is my code : If you run the code , you see that there are a lot of undefineds in the output.What would cause this ? Thanks ! | var encodings = { 0000 : 0 , 0001 : 1 , 0010 : 2 , 0011 : 3 , 0100 : 4 , 0101 : 5 , 0110 : 6 , 0111 : 7 , 1000 : 8 , 1001 : 9 , 1010 : `` + '' , 1011 : `` - '' , 1100 : `` * '' , 1101 : `` / '' } ; var chromosome = `` '' ; for ( var i = 0 ; i < 36 ; i++ ) { chromosome += Math.round ( Math.random ( ) ) ; } var chromArra... | Javascript not reading array items beginning with 0 |
JS | I 'm seeing the following behaviour , in the middle of a javascript debug session : which makes me wonder - can a function , ever not be object ? [ running on Chrome 29 , on a mac ] Note that this is in the middle of a very complex debug session . I do n't exactly know where ' o ' is coming from , or how it was created... | o // function ( a1 , a2 , a3 ) { return a1 + a2 + a3 ; } typeof ( o ) //'function'for ( var n in o ) { console.log ( n ) ; } // < a list of properties > Object.keys ( o ) //TypeError : not an objectObject.prototype.toString.call ( o ) ; // '' [ object Function ] '' var t = function ( ) { return true ; } //undefinedt.a ... | When is a javascript function not an object ? |
JS | This pattern is quite common ; I 've seen it in a few places including the jQuery source code : as an alternative to the 'normal ' methods of array initiliasation : What are the benefits of the string-splitting approach ? | var arr = `` word1 word2 word3 '' .split ( `` `` ) ; var arr1 = [ `` word1 '' , `` word2 '' , `` word3 '' ] ; var arr2 = new Array ( `` word1 '' , `` word2 '' , `` word3 '' ) ; | What are the advantages of splitting a string to initiliase a javascript array ? |
JS | We 've found several examples of pre-populating selected option for Select2 , however none of them we could find deal with formatted list and selection options . We have a JS fiddle at https : //jsfiddle.net/gpsx62de/26/ that illustrates the issue . In that fiddle , you can type and L or whatever into the select search... | // Set up the Select2 control $ ( ' # mySelect2 ' ) .select2 ( { ajax : { url : '/api/students ' } } ) ; // Fetch the preselected item , and add to the controlvar studentSelect = $ ( ' # mySelect2 ' ) ; $ .ajax ( { type : 'GET ' , url : '/api/students/s/ ' + studentId } ) .then ( function ( data ) { // create the optio... | How can ajax based Select2 pre-population be formatted ? |
JS | The code below was working and it should listen for changes in a node and execute a function but now am getting an error : So , in my angular2 component I have : So where am I going wrong as getting the error above which point to : What I need my code to do is to listen to whenever there is a change in a firebase node ... | ncaught TypeError : Object ( ... ) is not a functionat SwitchMapSubscriber.eval [ as project ] ( changes.js:7 ) private subscriptions = new Subscription ( ) ; registered : AngularFireList < any > ; constructor ( private _af : AngularFireDatabase ) { this.registered = _af.list ( '/registered ' ) ; } ngOnInit ( ) { this.... | Angular2 fire listen to node changes throws an error |
JS | Can anyone explain why document.write part always outputs 10 ? I think the answer to this question is more thorough than the duplicate question , therefore worth keeping this post . | function creatFunctions ( ) { var result = new Array ( ) ; for ( var i = 0 ; i < 10 ; i++ ) { result [ i ] = function ( ) { return i ; } } return result ; } var funcs = creatFunctions ( ) ; for ( var i = 0 ; i < funcs.length ; i++ ) { document.write ( funcs [ i ] ( ) + `` < br / > '' ) ; } | JavaScript closure and scope chain |
JS | I 'm struggling with some regex , in javascript which does n't have a typical lookbehind option , to only match a group if it 's not preceded with a string : so in the following I 'm trying to detect if the www.mytestwebsite.com is preceeded by and if it is I do n't want to match , otherwise match away . I tried using ... | ( ^| ) ( www\. [ \S ] + ? ( ? = & # x20 ; | [ , ; : ! ? ] |\ . ( & # x20 ; ) | $ ) ) hello & # x20 ; http & # x3a ; & # x2f ; www.mytestwebsite.com & # x20 ; is & # x20 ; awesome & # x2f ; ( ^| ) ( ( ? ! & # x2f ) www\. [ \S ] + ? ( ? = & # x20 ; | [ , ; : ! ? ] |\ . ( & # x20 ; ) | $ ) ) | Regex - Do n't match a group if it starts with a string in javascript |
JS | So I 'm trying to display child components at specific locations in my Component.I have the following : I tried to display it using < ng-content select= '' item '' > but that did n't work.With the following : the expected output ishttps : //stackblitz.com/edit/angular-ivy-2aibgt | @ Component ( { selector : 'app-item-list ' , template : ` < p *ngFor= '' let item of items '' > { { item.order } } < ! -- display content of child component here -- > < /p > ` } ) export class ItemListComponent implements OnInit , AfterContentInit { //Get all child components of the type ItemComponent and store them .... | Displaying content of Component that i fetched with @ ContentChildren or @ ViewChild |
JS | Could anyone explain why the two below are not equal ? I 'm basically trying to figure out what 's happening behind the scenes . My understanding was that they 'd both refer to the same function but that does n't seem to be the case . | var foo = function bar ( ) { } typeof foo // '' function '' typeof bar // '' function '' foo === bar //falsefoo == bar //false | Function references - Please enlighten ! |
JS | Below code snipped throws an error TypeError : myObj.prototype is undefined . Could someone explain me why ? Why there is no prototype for new Object ( ) & object literals as specified below ? If this is not valid approach then how can I achieve this ? | var myObj = { a : `` This is a '' , b : `` This is b '' } myObj.prototype.c= `` This is c '' ; // TypeError : myObj.prototype is undefined | Why this JS code is not valid ? |
JS | I want to stop the fading out of a JQueryUI menu . Same context : FireFox 43 , Linux/Debian/Sid , Jquery2.2 , JqueryUI1.11.4 , as for this question ; the alpha-stage MELT monitor , GPL free software on Linux/Debian with recent Firefox 38 or 43 on Linux ; this is commit b505eccc1 ... on github ( JsFiddle MVCE example at... | var curmenu = mom_menucmdel ; curmenu.mousemove ( function ( ev ) { console.log ( `` momdelayrepl movefinishing ev= '' , ev , `` curmenu= '' , curmenu ) ; curmenu.finish ( ) ; } ) ; setTimeout ( function ( ) { console.log ( `` mom_cmdkeypress-delayedreplmenudestroy curmenu= '' , curmenu ) ; curmenu.delay ( 100 ) .fadeO... | How to abort fading out of jqueryui menu ? |
JS | I have been playing around with PHP and JavaScript and jQuery and installed a couple of jQuery plugins . Now in my header I have : Is this loading two different things ? Or can I get rid of one ? | < script type= '' text/javascript '' src= '' http : //ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js '' > < /script > < script type= '' text/javascript '' src= '' http : //ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js '' > < /script > | By including jQuery and jQuery UI , Am I loading jQuery twice ? |
JS | I took the examplefrom the documentation page https : //flowtype.org/docs/union-intersection-types.html # _And this code type checks without errors.For me the result is not immediately obvious.As they show somewhere near the top of the page with another example : the intersection ( which flows from the term semantics i... | /* @ flow */class Foo { } class Bar { } declare var f : ( ( x : Foo ) = > void ) & ( ( x : Bar ) = > void ) ; f ( new Foo ( ) ) ; /* @ flow */type I = { a : number } & { b : number } ; var x : I = { a : 1 , b : 2 } ; x = { a : 1 , b : 2 , c : `` three '' } ; | Why does intersection type for functions accept either of type declarations not both ? |
JS | We are writing site logic which its design was made by another company . ( they sent us the html files ) However when we looked at their source code html we saw : 1 ) modernizr.js2 ) creation of html5 element scripts :3 ) Html5 shiv JS : 4 ) reference to css3-mediaqueries.js for media queries5 ) Respond.js v1.1.0 min/m... | < ! -- [ if lt IE 9 ] > < script > document.createElement ( 'header ' ) ; document.createElement ( 'nav ' ) ; document.createElement ( 'section ' ) ; document.createElement ( 'article ' ) ; document.createElement ( 'aside ' ) ; document.createElement ( 'footer ' ) ; < /script > < ! [ endif ] -- > < ! -- [ if lt IE 9 ] ... | Html5 helper files ? |
JS | Here is the result from browser console ( both firefox and chrome ) , false == { } works , but { } == false gives syntax error . | > > false == [ ] true > > false == { } false > > 0 == falsetrue > > false == [ ] true > > false == { } false > > [ ] == falsetrue > > { } == falseUncaught SyntaxError : Unexpected token == | Why is `` { } == false '' incorrect javascript syntax , while `` false == { } '' is not ? |
JS | It alerts `` hello world ! ! ! `` , why ? Can I modify prototype method , if yes how ? | var p = function ( ) { this.show = function ( ) { alert ( 'hello world ! ! ! ' ) ; } } p.prototype.show = function ( ) { alert ( 'haha ' ) ; } var o = new p ( ) ; o.show ( ) ; | Why is n't the function declared in the prototype called ? |
JS | What is difference / similarities between calling a function like the following ? What is the purpose of having these two ways ? What are their pros and cons ? Can someone explain how this call works - > sum ( 2 ) ( 3 ) ; ? And mention other conventional equivalent of this call ? The sum function for both this call can... | function sum ( x ) { if ( arguments.length == 2 ) { return arguments [ 0 ] + arguments [ 1 ] ; } else { return function ( y ) { return x + y ; } ; } } console.log ( sum ( 2,3 ) ) ; // Outputs 5console.log ( sum ( 2 ) ( 3 ) ) ; // Outputs 5 | JavaScript invoking a function in different ways |
JS | I came across this in code generated by Babel from this source . It would appear to be guarding a required function , somehow.I understand how the comma statement in the parenthesis discards the 0 and returns the validateNextState function , but why not just do : My guess is a type of guard ( like closures guard scope ... | ( 0 , _utilities.validateNextState ) ( nextDomainState , reducerName , action ) ; _utilities.validateNextState ( nextDomainState , reducerName , action ) ; | What is the purpose of calling ( 0 , func ) ( ) in JS ? |
JS | Consider a stylesheet that resizes the page as the height diminishes using media queries and transform : The page `` zooms out '' as the window height diminishes , allowing the full content to be displayed on smaller screens.If I want to support screens smaller than 560px height , I need to add more media queries.Notic... | @ media ( max-height : 620px ) { body { transform : scale ( 0.95 ) ; } } @ media ( max-height : 590px ) { body { transform : scale ( 0.90 ) ; } } @ media ( max-height : 560px ) { body { transform : scale ( 0.85 ) ; } } // and so on ... | Incremental CSS Media Queries |
JS | I have a function in which I 'm using closure as follows : the variable bigjsondata contains a large dataset . The question is : does it allocate memory for bigjsondata whenever I create a variable var a = myobject ( ) ? Can it lead to memory problems if a lot of instances are created ? If so what is the best way to lo... | function myobject ( ) { var width=300 , height=400 , bigjsondata = { } // assume this is a big variable ~ 300k function obj ( htmlelement ) { // plot a graph in this htmlelement based on bigjsondata } return obj ; } var plot1 = myobject ( ) ; plot1 ( ' # holder1 ' ) ; var plot2 = myobject ( ) ; plot1 ( ' # holder2 ' ) ... | Can storing large variables in a closure cause problems ? |
JS | I am writing a plugin that is given a id . it adds some code to that id and starts some events . the problem I have found is if the container is later overwriten I ca n't find a way to shut down the events so they do n't keep running . Below is a demo script to show what I have tried . I ca n't seem to find anyway to d... | $ ( function ( ) { /* ********************************* * Simple example of something that could be done * being told to work on id test2 ********************************* */ var a=0 ; $ ( `` # test2 '' ) .append ( ' < br > I Ran ' ) ; var id=setInterval ( function ( ) { console.log ( `` running '' ) ; //ctrl+shift+j w... | Detecting DOM item removed in javascript |
JS | The following is a code snippet from Crockford 's JavaScript : The Good Parts : Crockford goes onto explain that `` By augmenting Function.prototype with a method method , we no longer have to type the name of the prototype property . That bit of ugliness can now be hidden . `` I 'm basically at a loss to understand th... | Function.prototype.method = function ( name , func ) { this.prototype [ name ] = func ; return this ; } ; | Implicitly add methods to constructor 's prototype in JavaScript |
JS | How to set value in object in Javascript when you do n't know the key pattern ? Example : Key value is same , but some time it is in CAPITAL or some time it is in lowercase or sometime the first letter is in uppercase and other lowercase.In my example , I want to set perm city value but I do n't know which pattern it w... | var a = { 'perm city ' : { value : 'asda ' } } if ( ( a [ 'perm city ' ] & & a [ 'perm city ' ] .value ) || ( a [ 'Perm City ' ] & & a [ 'Perm City ' ] .value ) || ( a [ 'PERM CITY ' ] & & a [ 'PERM CITY ' ] .value ) ) { a [ 'PERM CITY ' ] = 'DADASDASD ' } | How to case-insensitively set value in object in Javascript ? |
JS | I 'm building an autosuggest for names . When the user types in the textbox , it hits the server and runs this : How can I make this faster ? I 'm using Node.js | var names = [ list of 1000 names ] ; //I have a list of 1000 names , this is static.var query = 'alex ' ; var matched_names = [ ] ; //This is when it gets slow ... .names.forEach ( function ( name ) { if ( name.indexOf ( query ) > = 0 ) { matched_names.push ( name ) ; } } ) ; return matched_names ; | How do I match this text faster ? |
JS | I have a list of shortcuts : and a body of text of various capitalisation : Is it possible to replace all the words in the text that match the shortcut list with a capitalised version of the shortcut using regex ? Is it possible to do that without a loop only using String.prototype.replace ( ) ? The desired outcome in ... | var shortcuts = [ `` efa '' , '' ame '' , '' ict '' , '' del '' , '' aps '' , '' lfb '' , '' bis '' , '' bbc '' ... var myText = `` Lorem ipsum ... Efa , efa , EFA ... '' ; myText = `` Lorem ipsum ... EFA , EFA , EFA ... '' ; | regex - efficiently capitalize all shortcuts from given list in a text |
JS | I want to display two html tables using different table id 's . I am able to display one table but I am not able to display the second table and not figure it out where I am making error . Code is given below : I want to show second table when i click on values of column2 . Kindly guide me how to fix this issue . Here ... | var $ container = $ ( `` # container '' ) ; var $ row = $ ( `` # container table tbody tr '' ) ; // Loop through items in JSON data.. var $ button = $ ( `` < button > '' + 'xyz ' + `` < /button > '' ) ; $ container.prepend ( $ button ) ; var table = $ ( `` < table1 > '' ) ; table.append ( $ ( `` < tr > < th > column1 <... | How to show two html tables using different table id 's ? |
JS | The following code always prints the argument passed in to parameter a , regardless of the presence of a variable with the same name.Presumably because parameter identifiers are bound separately to variables in scope . Where are they positioned ? Are they in the lexical environment ? Is it that var declarations end up ... | function foo ( a , b = ( ) = > a ) { var a = 1 console.log ( b ( ) ) } foo ( ) // undefinedfoo ( 2 ) // 2 | Where are arguments positioned in the lexical environment ? |
JS | Bit of a weird problem here - so I will try to explain this as clearly as possible.I have a simple ng-repeat that will show content based on what has a key value of .active set to true . I let the user scroll through the content with some arrow buttons bound to some ng-clicks . This works great , however I want to excl... | //flip right $ scope.flipRight = function ( index , parent ) { var idx = index + 1 ; if ( idx > = $ scope.contentHere [ parent ] .sides.length ) { idx = 0 ; } $ scope.contentHere [ parent ] .sides [ index ] .active = false ; $ scope.contentHere [ parent ] .sides [ idx ] .active = true ; } ; //flip left $ scope.flipLeft... | angular , skipping over a value if it has a certain key/value |
JS | I recently wanted to walk somebody through how Array.prototype.sort uses a custom method to compare two values at any given time , and decide whether they should be swapped or left alone . I decided to log the array during each comparison so the result of the previous comparison could be seen . When I logged the array ... | var num = [ 2 , 1 , 8 , 5 , 3 ] ; num.sort ( comparator ) ; function comparator ( a , b ) { console.log ( num ) ; // Current state of num return a - b ; // Order values numerically } [ 2 , 1 , 8 , 5 , 3 ] // Comparing 2 and 1 [ 1 , 2 , 8 , 5 , 3 ] // Comparing 2 and 8 [ 1 , 2 , 8 , 5 , 3 ] // Comparing 8 and 5 [ 1 , 2 ... | Array.prototype.sort Temporarily Duplicating Content ? |
JS | ProblemUsing delete on an array element to remove it from the array is the only way I 'm aware of to remove an element from an array such that a .forEach ( ) call skips the index . QuestionsDoes using the delete on an index , exampleArray [ i ] for example , cause a subsequent exampleArray.push ( ) to increase the memo... | var exampleArray = [ ] ; var n = 500 ; //Does this line imply a memory allocation ? exampleArray.length = n ; exampleArray.fill ( `` Lorem Ipsum '' , 0 ) ; exampleArray.forEach ( function ( cur , ind , arr ) { if ( ind % 4 === 0 ) { delete arr [ ind ] ; //Actually deletes the object itself , index no longer exists //Le... | Does using delete and subsequently .push ( ) on an array effect performance / memory consumption ? |
JS | I 'm trying to retrieve products from my Shopify store with this code , a near copy/paste of the examples page for the Javascript Buy SDK : Here 's a fiddle.The buildClient command seems to complete successfully , however I get a console error with the next two commands : Error : Not Found . I assume this refers to the... | $ ( function ( ) { var shopClient = ShopifyBuy.buildClient ( { accessToken : '4b4e3d4bba63039f2d51db94c2e79a46 ' , domain : 'squatch-air-clutches-test.myshopify.com ' , appId : ' 6 ' } ) ; shopClient.fetchQueryProducts ( { collection_id : 1397227547 } ) .then ( function ( products ) { $ ( '.test ' ) .append ( JSON.stri... | Javascript Buy SDK - Error : Not Found |
JS | am trying to focus the scroll based on the selected add class , when clicking on the previous and next button the scroll need to focus it . how can i make it possible please check my fiddle https : //jsfiddle.net/kannankds/bcszkqLu/ | < ul class= '' kds '' > < li > tile dtls1 < /li > < li > tile dtls2 < /li > < li > tile dtls3 < /li > < /ul > < input type= '' button '' value= '' previous '' class= '' previous '' > < input type= '' button '' value= '' next '' class= '' next '' > | how to focus the scroll based on the current selection class |
JS | I 'm working on debugging some code someone else wrote ( using Mootools as the base library ) , and I came across this function : I 've never seen this syntax before , with the brackets and the $ H notation ( eg . [ note , $ H ( options.text ) .getKeys ( ) ] ) . Can anyone explain how that works or point me to a refere... | [ note , $ H ( options.text ) .getKeys ( ) ] .flatten ( ) .each ( function ( option ) { // bunch of stuff happening } ) ; | strange syntax in javascript |
JS | I havean array of user addressesMy goalis to grab the lat , and lng of each address , and construct something like thisso I can plot them in Google Map.I tried : making a curl to $ data = shell_exec ( 'curl '. $ url ) ; I gotthis back as a response , after decode it $ data = json_decode ( $ data ) ; As you can see , no... | array:5 [ ▼ 0 = > array:2 [ ▼ `` name '' = > `` Admin '' `` address '' = > `` 111 Park AveFloor 4 New York , NY '' ] 1 = > array:2 [ ▼ `` name '' = > `` User A '' `` address '' = > `` 12 Main Street Cambridge , MA '' ] 2 = > array:2 [ ▼ `` name '' = > `` Apple HQ '' `` address '' = > `` 1 Infinite Loop Cupertino , Cali... | Get the lat , lng base on address |
JS | I 'm retrieving some images from one of my chrome extension folders to the website DOM and everytime I reload the extension I 'm getting a 'Extension Context Invalidated ' error . Same thing happens when I do a 'chrome.storage.local.set'.Doing some research I have realized that this error has to do with the facts well ... | for ( let k = 0 ; k < incomingChatTags.length ; k++ ) { let normalHolderTag = $ ( incomingChatTags [ k ] ) .text ( ) .toLowerCase ( ) ; switch ( normalHolderTag ) { case `` vip '' : $ ( incomingChatTags [ k ] ) .addClass ( `` ce-vip '' ) ; priorityVal += 300 ; break ; case `` rg '' : $ ( incomingChatTags [ k ] ) .addCl... | Chrome Extension : Extension context invalidated when getting URL |
JS | I 've seen a couple of pages load their javascript files into a page via new Image.src = '' ; I was just wondering the benefits or purpose of this . | < script type= '' text/javascript '' > new Image ( ) .src = `` XXXX\/js\/jquery-1.7.2.min.js '' ; < /script > | Downloading a Javascript Library as an image ? |
JS | I 'm perusing the AngularJS source code and could n't help but notice the following : This line makes sense to me : '' Use angular if already defined ( from a previous inclusion ? ) in window , or assign window.angular to an empty object and set angular local variable to window.angular . `` Some questions : Why would w... | _angular = window.angular , /** @ name angular */angular = window.angular || ( window.angular = { } ) , angular = window.angular || ( window.angular = { } ) , | JavaScript variable declaration in AngularJS |
JS | I just stumbled upon a line of code in a project I 'm currently working in . I feel I 'm decent at Javascript but to be honest , I have no clue as of what the following line of code actually does : Can someone of you Javascript gurus possibly shed some light on this ? buildDateParams seems to build an array of values .... | var date = new ( Function.prototype.bind.apply ( Date , [ null , ] .concat ( buildDateParams ( spec , base ) ) ) ) ; function buildDateParams ( spec , base ) { if ( ! spec.match ( specRegExp ) ) { throw new Error ( 'Invalid spec string ' ) ; } var specParts = spec.toLowerCase ( ) .split ( ' : ' ) ; let params = [ ] ; f... | What could this line of Javascript code possibly do ? |
JS | So , I learn git functions , but can not make the file README.md executed from git branch update in the file .gitignore.I had wrote the next in .gitignore but it does not help during push on server . | // .gitignore # readmeREADME.mdLICENSE | How to restrict git from tracking / updating local changes ? |
JS | I am using bar-ui js of soundmanager.I have many players so i do n't know about soundid what i want to when page load player should load.See i have three player on my page i want ... . I tried that But the problem i can get sound-id until i play otherwise i did not able to get id.Is there any way to get id when page lo... | http : //www.schillmania.com/projects/soundmanager2/demo/bar-ui/ http : //support.simplepodcaster.com/auto-timestamps/ var mySoundObject = soundManager.createSound ( { id : 'mySound ' , url : '/audio/mysoundfile.mp3 ' , // optional sound parameters here , see Sound Properties for full listvolume : 50 , autoPlay : true ... | Want to know about SounManager Player ID |
JS | We have a CMS so I do n't have access to the header of the HTML page which gets rendered for our extjs implementation . So I had to make a workaround which is like this : The problem I 'm having is that the minified version gets ignored completely . I see it load on the http request but extjs ignores them ... . even th... | Ext.local = { } ; var lang = { initLang : function ( revisionNr ) { var local = localStorage.getItem ( 'localLang ' ) if ( ! local ) { AjaxHandlerByClass ( 'ajax/lang/webuser/init ' , { } , this.loadLangRemote ) ; } else { local = JSON.parse ( local ) ; if ( local.revisionNr == config.revisionNr & & local.lang == confi... | ExtJs minify Gets ignored |
JS | I 'm loading a script file via AJAX , and to run its content I 'm doing this : However , according to MDN : Function objects created with the Function constructor are parsed when the function is created . This is less efficient than declaring a function and calling it within your code , because functions declared with ... | new Function ( 'someargument ' , xhr.responseText ) ( somevalue ) ; | Use of ` new Function ` and performance issues |
JS | What is the difference between these two statements ? They give different output ( in google chrome console ) .Test { } undefinedMind = boggled | function Test ( ) { if ( this instanceof Test ) { } else { return new Test ( ) ; } } x = Test ( ) ; function Test ( ) { if ( ! this instanceof Test ) { return new Test ( ) ; } } x = Test ( ) ; | Negation of instanceof gives unexpected results |
JS | I saw , some days ago , an alternate way to use functions on jQuery event bindings . It consists on : first declare the function , and then call it on the binding , like as follows . I think the code remains better organized.I have n't found any article explaining if this is a good practice.My doubt is : can this wreak... | //Função para capturar e passar os elementos para a função de apply.function invokeSequentialFade ( ) { //code ... } ; //Função para Instanciar o carousel de acordo com o dispositivo.function invokeCarousel ( ) { //code ... } ; //Função para instanciar o scrollfade ( elementos surgirem no scroll ) .function invokeScrol... | Declare function and call it on jquery event binding |
JS | How do I use a template-helper to edit the value of the parameter I passed into a route created using the pathFor method of iron-router ? ? ? I have this template-helper : in my .html file I have this : The { { this } } in the above code returns a string , the name of the category.Because I have registered a template h... | Template.registerHelper ( 'slugify ' , function ( obj ) { return _.slugify ( obj ) ; } ) ; { { # each menuItemsFromDB } } { { # each arrayOfMenuItems } } < a class= '' item category '' href= '' '' > { { this } } < /a > { { /each } } { { /each } } { { slugify this } } this.route ( 'List ' , { path : '/list/ : category_s... | How Do I Use a Meteor Template Helper to Edit a Value Passed as a Parameter in Iron-Router ? |
JS | I 'm trying to make an improvement to an existing Gatsby plug-in , and I want to pass a React Component to the plug-in , through its configuration entry in gatsby-config.js : However , the problem I 'm running into is that I ca n't figure out how to make it work.If I try to pass the component itself as part of the plug... | plugins : [ { resolve : ` gatsby-plugin-modal-routing ` , options : { someComponent : SomeComponentClassOrFunction } } , plugins : [ { resolve : ` gatsby-plugin-modal-routing ` , options : { modalComponentPath : path.join ( __dirname , 'src/components/SomeComponent.js ' ) } } , | Gatsby Plug-in : How Can I Take a Component as a Plug-In Option ? |
JS | On my real Android device , focusing a TextInput after pushing a screen into a Stack Navigation makes the keyboard flashing once ( appears then disappears immediately ) . This does n't occur on refocusing , but reoccurs if I navigate back and re-push the navigation with any screens that has TextInputs in it.This does n... | import * as React from 'react ' ; import { NavigationContainer } from ' @ react-navigation/native ' ; import { createStackNavigator } from ' @ react-navigation/stack ' ; import CategoryScreen from './screens/Category ' ; const MyStack = createStackNavigator ( ) ; export default function App ( ) { return ( < NavigationC... | React Native : After Navigate Push , First Focus TextInput Flashing Out Keyboard |
JS | Why does my button 's click event not register when the mouse pointer is in the spot shown in the screenshot below ? I 've created a jsFiddle for you to test it out . Make sure to check your browser 's console for feedback.http : //jsfiddle.net/27kRH/Here is my code , I 'm using jQuery | var clickCounter = 0 ; $ ( 'button ' ) .click ( function ( ) { clickCounter++ ; console.log ( 'times clicked : ' + clickCounter ) ; } ) ; | why does this button 's `` click '' not work on some regions of the button ? |
JS | In JavaScript , why is : What exactly makes it return 0 , and why is the following equal to NaN ? | new String * 1 < - 0 function Foo ( ) { this.bar = 0 ; } new Foo * 5 ; < - NaN | Why does new String * 1 return 0 in Javascript ? |
JS | Possible Duplicate : Explain JavaScript ’ s encapsulated anonymous function syntax i do n't understand completely what this does , so i wanted to look it up in google but I did n't find anything and realized that I do n't know its name ; so my question is : What is the name of this construction ( ? ) : Thanks in advanc... | ( function ( ... ) { } ) ( jQuery , window , document ) ; | What is the name of this ? |
JS | Apparently , back in Firefox 3.6 , the following was legitimate : and the result was '678'.FF8 is n't having any . What 's the right syntax now ? | / [ 0-9 ] { 3 } / ( '23 2 34 678 9 09 ' ) | javascript regular expressions as functions ? |
JS | Trying to build a chrome extension content script that adds an extra useful nav to a GitHub issue page . When interaction is done through the normal webpage ( the end user click an reaction emoji ) - my injected element gets lost.The only way I have been able to get around it is to set an interval that keeps removing a... | const URL = window.location.origin + window.location.pathname + window.location.searchconst header = document.querySelector ( ' # partial-discussion-sidebar ' ) header.style = ` position : relative ; height : 100 % ; ` let wrapper = getWrapper ( ) // // The isolated world made it difficult to detect DOM changes in the ... | Chrome extensions CORB : How to react to updates in the shared DOM |
JS | EDIT : My function was broken , with the /n in it . Thanks woofmeow for leading me to question my function ! I am new to programming . I have been trying my best and I have learned a lot the past few months ( a bunch here ! ) but I am stumped . I have a PHP script that calls from another PHP script and I can not get th... | < script type= '' text/javascript '' > function delete_user ( user_id ) { if ( confirm ( `` Are you sure you want to delete this user ? '' + `` \nThere 's really no going back ! '' ) ) { window.location = `` delete_user.php ? user_id= '' + user_id ; } } < /script > $ delete_user_script = < < < EODfunction delete_user (... | Using PHP to load Javascript |
JS | I 've looked around but I can not find any good documentation on what the actual differences are between the following : I do understand that .content seems to be the internal storage of the array for the property , which may not be available if this happens to be a PromiseArray . I also understand that @ each would no... | Ember.Object.extend ( { // ... myProperty1 : function ( ) { /* ... */ } .property ( 'myArray ' ) , myProperty2 : function ( ) { /* ... */ } .property ( 'myArray.content ' ) , myProperty3 : function ( ) { /* ... */ } .property ( 'myArray . [ ] ' ) , myProperty4 : function ( ) { /* ... */ } .property ( 'myArray . @ each ... | What 's the difference between [ ] , @ each , content , and < arrayName > in EmberJS ? |
JS | I came across a JS file which was built in a strange manner : I understand the part of wrapping a function into the `` modal '' object , but why bind all the functions to method and then return it at the end ? | var modal = ( function ( ) { var method = { } ; // Center the modal in the viewport method.center = function ( ) { } ; // Open the modal method.open = function ( settings ) { } ; // Close the modal method.close = function ( ) { } ; return method ; } ( ) ) ; | Advantage of using method in OOP Javascript |
JS | I 've encountered an `` unrecoverable stack overflow error '' that I ca n't figure out . From the docs : you need to create an interface object ( of any class ) and make it known to JavaScript by calling JSObject.setMember ( ) .Here 's the Java code sharing and using the interface object : And here 's the JavaScript co... | // somewhere in the codeJSObject window = ( JSObject ) engine.executeScript ( `` window '' ) ; window.setMember ( `` foo '' , new Foo ( ) ) ; // < -- shareswindow.call ( `` testFoo '' ) ; // < -- uses// somewhere elseclass Foo { public void bar ( ) { System.out.println ( `` baz '' ) ; } } window.testFoo = function ( ) ... | Unrecoverable stackoverflow error when making upcalls from JavaScript to Java |
JS | I already looked for similar questions , but they are related to JQuery or any other library.First , I wrote this : And used it in this way : I think then is very important , because it allows us to execute something as soon as the promise is resolved.But I was looking for something like this : I noticed I needed an ob... | const printIn1Sec = ( value ) = > { return new Promise ( resolve = > { setTimeout ( ( ) = > { console.log ( value ) ; resolve ( ) ; } , 1000 ) } ) ; } ; printIn1Sec ( 1 ) .then ( ( ) = > printIn1Sec ( 2 ) ) .then ( ( ) = > printIn1Sec ( 3 ) ) ; printIn1Sec ( 1 ) .printIn1Sec ( 2 ) .printIn1Sec ( 3 ) ; class Printer ext... | How to define a promise chain without using then method |
JS | While running through the starter tutorial on EmberJS ' site , a few things have me a little confused now.One thing to note immediately is that I decided to use the ember 1.9.0beta4 with handlebars 2.0.0 instead of 1.8.1 / 1.3.0 included in the starter pack.First the code included in the screencast : andThis works exac... | app.jsApp.Router.map ( function ( ) { this.resource ( 'about ' ) ; this.resource ( 'posts ' ) ; this.resource ( 'post ' , { path : ' : post_id ' } ) } ) ; App.PostsRoute = Ember.Route.extend ( { model : function ( ) { return posts ; } } ) ; index.html { { # each model } } < tr > < td > { { # link-to 'post ' this } } { ... | Models , naming , and this |
JS | I have the following HTML : And ( working ) jquery that toggles between them : I want to use CSS3 to create a fade effect as I toggle between them . I have tried the following : However , no animation takes place . What am I doing wrong ? | < div id= '' welcome-content '' > // Code < /div > < div id= '' configure-content '' style= '' display : none '' > // Code < /div > $ ( '.back-welcome ' ) .click ( function ( ) { $ ( ' # welcome-content ' ) .toggle ( ) ; $ ( ' # configure-content ' ) .toggle ( ) ; } ) ; # welcome-content , # configure-content { -webkit... | How to use CSS3 transitions |
JS | I have a code like : JsFiddleHere var index = [ 1,3 ] is the index value of the data to be set.What I want here is , to set the value of index i. e ball and dog after fish and the rest remains on the order.After inserted I want the index value to be changed according to the new position of the ball and dog i. e [ 4 , 5... | var data = [ `` apple '' , `` ball '' , `` cat '' , `` dog '' , `` elephant '' , `` fish '' , `` gorilla '' ] var index = [ 1 , 3 ] // ball and dogvar to = 5 // fishfor ( var i in index ) { console.log ( index [ i ] ) var local_data = data data.splice ( to , 0 , data.splice ( index [ i ] ) , 1 ) } console.log ( data ) ... | javascript add and remove multiple value from a list in and from specific index |
JS | I have a collection of nested comments . My goal is to display a 'reply ' option when hovering each comment separately . This means that I do n't want the 'reply ' option to show up for parent/sibling/children of the comment I am hovering.The only similar question I have found is : Can I control CSS selection for : hov... | .comment { padding : 10px ; border : 1px solid black ; margin-top : 10px ; } .text { } .comment : hover > .reply { display : inline-block ; } .reply { display : none ; } .children-comments { margin-left : 50px ; margin-top : 10px ; } < div class= '' comment '' > < a class= '' text '' > wohoo < /a > < a class= '' reply ... | Selecting only immediately hovered element in CSS for nested elements |
JS | I am trying to solve the below problem in JavaScriptThe count-and-say sequence is the sequence of integers beginning as follows : So I want to create a function which pass N integer and gives it valueHere is my code : I do n't understand the logic for how to build this . | 1 , 11 , 21 , 1211 , 111221 , ... 1 is read off as one 1 or 11.11 is read off as two 1s or 21.21 is read off as one 2 , then one 1 or 1211.Given an integer n , generate the nth sequence.Note : The sequence of integers will be represented as a string.Example : if n = 2 , the sequence is 11. let countAndSay = function ( ... | how to build count and say problem in javascript |
JS | After many research , I 've been unable to correctly test an Angular directive , since I ca n't access to functions inside its controller.Here is the directive code : And my test : According to many documents I 've read , after the $ digest ( ) function we can have access to the controller of the directive . This is no... | angular.module ( 'app ' ) . directive ( `` accordionItem '' , function ( ) { return { restrict : ' E ' , replace : true , templateUrl : function ( elem , attr ) { return 'partials/invoice/ ' + attr.temp + '.html ' ; } , scope : { invoice : '= ' , temp : ' @ ' } , controller : function ( $ scope , listSelectionService ,... | How to test controller directives in AngularJS |
JS | A very puzzling problem i am having with JavaScript . look at the code below..in the code if you notice we have a class defined inside an object az.classes . when try to create an instance of that class by new az.classes [ 'test ] ( ) , it works and a.hello ( ) executes fine . but when i call the method az.getClass ( '... | az= { classes : { test : function ( ) { this.hello=function ( name ) { alert ( 'hello '+name ) ; } } } , getClass : function ( name ) { return az.classes [ name ] ; } } ; var a=new az.classes [ 'test ' ] ( ) ; a.hello ( 'foo ' ) ; var b= new az.getClass ( 'test ' ) ( ) ; b.hello ( ) ; // fails ! ! ! | Puzzling Javascript constructor issue |
JS | Given the following code , what should I expect to see in the alert ? My initial thought was that my browser should alert 100 since the variable a=100 would be in scope for the anonymous function passed as an argument to afunc . But this assumes that the anonymous function is actually defined in the global context . Ap... | var a = 100 ; function afunc ( infunc ) { a = 10 ; infunc.call ( ) ; } afunc ( function ( ) { alert ( a ) } ) ; | Scope of anonymous function passed as function argument |
JS | I am developing an addon , when user selects a value and right click on context menu .. properties of that object must be stored.Below is my code Main.jsbelow is the test.js where i wanted to take selectiontext object and print its innerhtmltest.jsbelow are some issues which i am facing , please kindly help mei am not ... | var contextMenu = require ( `` sdk/context-menu '' ) ; var menuItem = contextMenu.Item ( { label : `` Log Selection '' , context : contextMenu.SelectionContext ( ) , contentScript : 'self.on ( `` click '' , function ( ) { ' + ' var text = window.getSelection ( ) .toString ( ) ; ' + ' self.postMessage ( text ) ; ' + ' }... | Firefox add-on : passing value from context menu to contentScriptFile after selection |
JS | I have a component , that `` lazy loads '' some comments , at the interval of 100ms . When I use setTimeout , it is really laggy . componentThis makes my Application laggy ( avg fps 14 , idle time 51100ms ) : This make my Application smooth ( avg fps 35 , idle time 40800ms ) Is there any explaination , why the rxjs tim... | < div *ngFor= '' let post of posts '' > < app-post [ post ] = '' post '' > < /app-post > < /div > while ( this.postService.hasPosts ( ) ) { setTimeout ( ( ) = > { this.posts.push ( this.postService.next ( 10 ) ) ; } ,100 ) ; } while ( this.postService.hasPosts ( ) ) { timer ( 100 ) .subscribe ( ( ) = > { this.posts.pus... | Why does setTimeout ( ) make my app laggy , but Rxjs timer ( ) .subscribe ( ... ) does not ? |
JS | I have created a JavaScript file as a PHP file in my CodeIgniter views so that I can access some of my PHP dynamic variable in JavaScript.For example : Is this OK ? | $ .ajax ( { url : `` < ? php echo base_url ( 'loginpage ' ) ; ? > '' , type : 'POST ' , data : { emailId : email1 , password : pwd1 } , success : function ( result ) { | is it ok to write Javascript or jQuery code as a PHP file in CodeIgniter views ? |
JS | I was reading Secrets of the JavaScript Ninja and came across a coding example : If I uncomment the second commented line , samurai.yell ( 4 ) runs fine , I understand it as samurai still has its reference to the function originally referenced by ninja.yell , which delete removed.However , if I run the first commented ... | var ninja = { yell : function ( n ) { return n > 0 ? ninja.yell ( n-1 ) + `` a '' : `` hiy '' ; } } ; var samurai = { yell : ninja.yell } ; //var ninja = { } ; //delete ninja ; samurai.yell ( 4 ) ; | Difference between assigning an object to undefined and delete |
JS | My assumption is that time always runs forward , but apparently sometimes it doesn ’ t happen this way.I have the following example : Now , most of the time it works as expected , and diff shows a number close to 100 . Of course , in the real-life scenario I ’ d expect the number to go up , especially when the user ’ s... | var LOOP_MS = 100 ; var prevCall = +new Date ( ) ; setTimeout ( function loop ( ) { foobar ( ) ; setTimeout ( loop , LOOP_MS ) ; } , LOOP_MS ) ; function foobar ( ) { var now = +new Date ( ) , diff = now - prevCall ; // expected to be somewhere around LOOP_MS // do stuff console.log ( diff ) ; prevCall = now ; } | Current time is older than the previously saved time |
JS | I 've seen this idiom show up in various open-source projects : I know the second half can not be true in ECMAScript 5 ( or 6 ) , but is/was there ever an implementation that would return `` array '' from typeof ? Or is this a case of bogus defensive programming ? | it instanceof Array || typeof it == `` array '' | Has JavaScript typeof ever returned `` array '' ? |
JS | My game works with other browsers but with Firefox , there is a one small but major issue . Why firefox does not emit the `` new-player '' message after socket connection , other browsers work OK , all browsers output HELLO to console ... and register themself.problem on server side : new-player message not received wi... | const newPlayer = ( socket , player ) = > { socket.on ( 'connect ' , ( ) = > { console.log ( `` HELLO this row appears in all browsers '' ) ; socket.emit ( 'new-player ' , { x : player.sprite.body.x , y : player.sprite.body.y , angle : player.sprite.rotation , playerName : { name : String ( socket.id ) , x : player.pla... | why firefox does not emit after connection ( client side ) |
JS | I have a table I have the id of the checkbox that I want to set as checked , but I can not do it and I do n't know why . I try with this , but nothing happens and I do n't have any kind of error message : | $ ( ' # medicalListTable input.type_checkbox [ id= '' sindicate-345 '' ] ' ) .prop ( 'checked ' , true ) ; $ ( 'input.type_checkbox [ id= '' sindicate-345 '' ] ' ) .prop ( 'checked ' , true ) ; $ ( 'input.type_checkbox [ id= '' sindicate-345 '' ] ' ) .attr ( 'checked ' , true ) ; < script src= '' https : //cdnjs.cloudf... | How to set checkbox in a table checked ? |
JS | Currently writing a little persistent queue library that will read/write lines to a text file . Here is the add method , for example : what I find quite awkward , is supporting event emitters and callbacks ( or event emitters and promises ) .In other words , for each method ( add , peek , remove ) on the queue , I need... | Queue.prototype.add = function ( line , cb ) { getLock ( this , err = > { if ( err ) { this.emit ( 'error ' , err ) ; releaseLock ( err , cb ) ; } else { fs.appendFile ( this.filepath , line , err = > { err & & this.emit ( 'error ' , err ) ; releaseLock ( err , cb ) ; } ) ; } } ) ; } ; | Implementing Observables into a persistent queue library |
JS | More specifically , greater-than-or-equal-to operations.Logically n > = k should be equal to n > k || n == k but that does n't seem to be the case.Why is it that this : produces false , false , false , true , true ? | var d1 = new Date ( 2018 , 1 , 16 ) ; var d2 = new Date ( 2018 , 1 , 16 ) ; console.log ( d1 > d2 ) ; console.log ( d1 < d2 ) ; console.log ( d1 == d2 ) ; console.log ( d1 > = d2 ) ; console.log ( d1 < = d2 ) ; | How does JavaScript evaluate greater-than and less-than operations ? |
JS | I have a Highcharts column plot that shows four series . I would like series one and two to be touching each another ( the two blue ones ) , then have a small gap , and then have series three and four touching each another ( the orange ones ) . Can this be done ? I have n't found a way to do it myself , and ca n't find... | $ ( function ( ) { var chart ; var defaultTitle = `` CT doses '' ; var protocolNames = [ 'Abdomen ' , 'Chest ' , 'Sinus ' ] ; $ ( document ) .ready ( function ( ) { chart = new Highcharts.Chart ( { chart : { renderTo : 'container ' , type : 'column ' , events : { drilldown : function ( e ) { parentSeriesIndex = e.point... | Add a gap between the second and third series in a Highcharts column plot with four series displayed |
JS | In order to insert GA code ( and pretty much any other JS library ) , the code snippet is : Why not : at the end of the body ? | < script > ( function ( i , s , o , g , r , a , m ) { i [ 'GoogleAnalyticsObject ' ] =r ; i [ r ] =i [ r ] ||function ( ) { ( i [ r ] .q=i [ r ] .q|| [ ] ) .push ( arguments ) } , i [ r ] .l=1*new Date ( ) ; a=s.createElement ( o ) , m=s.getElementsByTagName ( o ) [ 0 ] ; a.async=1 ; a.src=g ; m.parentNode.insertBefore... | Insert Front-End Library ( eg . Analytics ) : why not a simple < script > tag ? |
JS | I am using JQuery to calculate some totals figures and I have run into a problem.Let 's say I have two sets of inputs , each with a unique name.I want to cycle through each set of inputs at the same time so that I can check both for ( ! isNaN ) and ( length ! == 0 ) , and if the values are valid , I want to multiply th... | $ ( ' [ name= '' quantity\\ [ \\ ] '' ] ' ) $ ( ' [ name= '' price\\ [ \\ ] '' ] ' ) | Looping through two different selectors at the same time |
JS | Why do labels exist in javascript ? The above code does n't appear to need a label at all ( it works with or without the commented label name ) . And Considering Douglas Crockford has not condemned them entirely : LabelsStatement labels are optional . Only these statements should belabeled : while , do , for , switch.A... | var i = 0 ; usefulLabel : //why do I exist ? while ( i < = 10 ) { document.writeln ( i ) ; i++ ; if ( i > 5 ) break ; // usefulLabel ; } | Why do labels exist ? |
JS | If I have code that pulls down a jQuery object , and then makes some further calls on itIs it considered bad practice to subsequently ( and unnecessarily ) wrap that object in the jQuery function ? Does jQuery optimize superfluous calls like this ? | $ ( `` a.postSyncLink '' ) .click ( function ( ) { var resultsTarget = $ ( `` span '' , $ ( link ) .parent ( ) .next ( ) ) ; resultsTarget.html ( `` < img style='position : absolute ; ' src= ' '' + waitImgUrl + `` '/ > < span > Sync in progress < /span > '' ) ; $ .get ( $ ( this ) .attr ( `` data-url '' ) , function ( ... | Are extra $ ( ... ) calls bad ? |
JS | Example JSFiddle so you can get a better idea of what is going on http : //jsfiddle.net/brsXL/3/ ( open your console and view the logged vars object ) .I am building a parser and computer for a specific subset of maths in JavaScript , it takes an expression as a string from the user and allows them to use variables . T... | var Variable = function ( value ) { this.value = value || null ; } Variable.prototype.valueOf = function ( ) { return this.value ; } var a = new Variable ( 10 ) ; console.log ( a + 2 ) ; // = 12console.log ( a / 2 ) ; // = 5 var a = new Variable ( 10 ) ; console.log ( a += 2 ) ; // = 12console.log ( a ) ; // = 12 var o... | Performing assignment operations on an object |
JS | Let 's say that I 've got a page which extracts some image sources like so : Note that srcs is not a JavaScript Array but an array-like object ; we know this because of the fact that we can make jQuery API calls on objects returned by the selector and the fact that srcs.constructor ! = Array.The jQuery API provides a .... | < div id= '' d '' > < img src= '' foo.gif '' / > < img src= '' bar.gif '' / > < img src= '' gah.gif '' / > < /div > < script type= '' text/javascript '' > var srcs = $ ( 'div # d > img ' ) .map ( function ( ) { return this.src } ) ; // srcs = > [ 'foo.gif ' , 'bar.gif ' , 'gah.gif ' ] < /script > | Reason for .get ( ) without index in jQuery API ? |
JS | I wrote a function named search that I expected to be called when the link was clicked , as the code snippet below shows : However , the code does not work as I expected , which causes this error ( in Chrome ) when the link is clicked : Uncaught TypeError : search is not a functionI tried logging search to see why the ... | < script > function search ( ) { console.log ( 'Searching ' ) ; } < /script > < a href= '' # '' onclick= '' search ( ) ; '' > Click here < /a > < a href= '' # '' onclick= '' console.log ( search ) '' > Click here < /a > < script > function search ( ) { console.log ( 'Searching ' ) ; } < /script > < a href= '' # '' oncl... | Why does this anchor say `` search is not a function '' ? |
JS | I 'm trying to animate an image that should move randomly inside a div container borders . I found few solution here to set the animation border , but non where the image stays inside the div.I have a snip for example - I need the red square to move inside the yellow div , even if I scroll down the page.How can I achie... | $ ( document ) .ready ( function ( ) { animateDiv ( ) ; } ) ; function makeNewPosition ( $ container ) { // Get viewport dimensions ( remove the dimension of the div ) $ container = ( $ container || $ ( window ) ) var h = $ container.height ( ) - 50 ; var w = $ container.width ( ) - 50 ; var nh = Math.floor ( Math.rand... | Animate image within a div border |
JS | Given a jQuery plugin , what is the cleanest way to initialise it on a list of elements rendered by ng-repeat ? For example , i want to make a list of words draggable . In the controller i take the list from the API : And in the view i iterate on them : What is left is to run the plugin initialisation code , like in : ... | $ scope.words = Words.get ( ... ) < article ng-controller= '' WordsCtrl '' > < div class= '' word '' ng-repeat= '' word in words '' > { { word } } < /div > < /article > $ ( elem ) .children ( '.word ' ) .draggable ( ) | jQuery plugin and angular repeat |
JS | In the code below , is a [ href^= '' / '' ] a regular expression ? Why does it have the ^ symbol and what does it do ? Which click events will it/wo n't it respond to ? ( code source ) | $ ( document ) .on ( 'click ' , ' a [ href^= '' / '' ] ' , function ( e ) { e.preventDefault ( ) ; var href = $ ( e.currentTarget ) .attr ( 'href ' ) ; console.log ( 'click ' + href ) ; Backbone.history.navigate ( href , { trigger : true } ) ; } ) ; | What does ' a [ href^= '' / '' ] ' mean ? |
JS | I have a popup which has the following output ! The output is just one complete string with spaces and newline characters . But each line is concatenated to the previous line . So , each line can be adjusted individually.Since I have multiple such popups and multiple tests for each popup . Is there a way I can format t... | Test1 : Success : 200Test2 : Success : 200Test3 : Success : 200Test4 : Success : 200Test5 : Success : 404Test6 : Success : 401 Test1 : Success : 200Test2 : Success : 200Test3 : Success : 200Test4 : Success : 200Test5 : Success : 404Test6 : Success : 401 | Angular js - Format String in Modal with correct spaces |
JS | I 'm trying to understand the difference between an 'empty ' sparse array ( e.g . new Array ( 3 ) ) and an equivalent 'empty ' dense array ( array with 3 undefined entries ) .I can create an array with 3 undefined values these two ways : Dense ArraysIf I do console.log for either of these the result is : If I loop over... | var sparse = new Array ( 3 ) ; // orvar sparse = [ , , , ] ; var dense = Array.apply ( null , Array ( 3 ) ) ; // See dense array link below [ undefined , undefined , undefined ] console.log ( sparse.length === dense.length ) ; // truefor ( var i = 0 ; i < dense.length ; i++ ) { console.log ( i + ' : '+ ( dense [ i ] ==... | Why does ` .forEach ` work on dense arrays but not on sparse arrays ? |
JS | I am learning how to use props . After taking research in either my mother language or english , I could n't end up with a proper answer for my issue.Please tell me why this threw errors . This is the App.js file ( default ) and this is the component file ( Product7.js ) everything is fine except it returned an error a... | import React from 'react ' ; import './App.css ' ; import Product7 from './componentep7/Product7 ' ; function App ( ) { return ( < div > < nav className= '' navbar navbar-inverse '' > < div className= '' container-fluid '' > < a className= '' navbar-brand '' > Title < /a > < /div > < /nav > < div className= '' containe... | ReactJS Props Undefined |
JS | For this snippet , I 'm not surprised global variable ' a ' evaluates to be 5.http : //jsfiddle.net/MeiJsVa23/gZSxY/ : But how come for this code snippet , global variable ' a ' evaluates to be 10 and not 5 ? It 's as if the a = 5 never happened.http : //jsfiddle.net/MeiJsVa23/2WZ7w/ : | var a = 10 ; function func ( ) { a = 5 ; } func ( ) ; // expect global variable ' a ' to be modified to 5 ; alert ( a ) ; // and this prints out 5 as expected . No surprise here. var a = 10 ; function func ( ) { a = 5 ; var a = 23 ; } func ( ) ; // expect global variable ' a ' to be modified to 5 ; alert ( a ) ; // bu... | Puzzled by this JavaScript code snippet |
JS | I have a global service widgetService which holds data for a number of widgets , each identified by a widgetID . Each widget 's data can change at any time . I want to display a widget with a React component , say WidgetReactComponent.The react component shall take a widget ID as property and get the information to dis... | class WidgetReactComponent extends Component { constructor ( ) { super ( ) ; this.state = { data : widgetService.getWidgetData ( this.props.widgetID ) } ; this._onDataChange = this._onDataChange.bind ( this ) ; } _onDataChange ( newData ) { this.setState ( { data : newData } ) ; } componentDidMount ( ) { // React docum... | How to properly handle subscriptions depending on property |
JS | I have a problem in chrome ( 47 ) where when using an input of type number in combination with ng-model-options= '' { getterSetter : true } '' does not allow you to enter decimal numbers in the field.With getterSetter : ( not working ) Without getterSetter : ( works ) see plunker for a demohttp : //plnkr.co/edit/qu8UXC... | < input ng-model= '' amount '' ng-model-options= '' { getterSetter : true } '' step= '' 0.01 '' type= '' number '' > < input ng-model= '' _amount '' step= '' 0.01 '' type= '' number '' > | Angular 1.4.x numeric field with gettersetter not working for decimal numbers |
JS | For example , if I would like to display the current date on the p element : Why the last statement does not display the current date , but the second statement works ? | $ ( `` p '' ) .html ( 'Now is '+Date ( ) ) ; // good $ ( `` p '' ) .html ( 'Now is '+new Date ( ) ) ; // good $ ( `` p '' ) .html ( Date ( ) ) ; // good $ ( `` p '' ) .html ( new Date ( ) ) ; // bad | What 's the difference when new operator is applied ? |
JS | I am attempting to map through a rest parameter.MDN says : The rest parameter syntax allows us to represent an indefinite number of arguments as an array.So if ... numbers is an array , when I use map on it ie numbers.map ( ) , the array it 's mapping is [ 33,44,55 ] . How can I now map each element of the ... numbers ... | function checkLastDigit ( num1 , num2 , num3 ) { function collectDigits ( ... numbers ) { let digitsArr = [ ] ; digitsArr = numbers.map ( collectLastDigit ( ) ) ; return digitsArr ; } function collectLastDigit ( ) { return this.slice ( this.length - 1 ) } return collectDigits ( num1 , num2 , num3 ) ; } checkLastDigit (... | How to map through a rest parameter ? |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.