lang stringclasses 4
values | desc stringlengths 2 8.98k | code stringlengths 7 36.2k | title stringlengths 12 162 |
|---|---|---|---|
JS | I have css class names - .exp-1 , .exp-2 , .exp-3 , exp-4 ... so is there any simple way to write these all in onlike line like , I m beginner to javascript to | document.getElementsByClassName ( `` exp-1 '' ) [ 0 ] ; document.getElementsByClassName ( `` exp-2 '' ) [ 0 ] ; document.getElementsByClassName ( `` exp-3 '' ) [ 0 ] ; document.getElementsByClassName ( `` exp-4 '' ) [ 0 ] ; document.getElementsByClassName ( `` exp-1 , exp-2 , exp-3 , exp-4 '' ) [ 0 ] ; | How to do mutiple css class in one line javascript code |
JS | I have asp.net web application located on server I want to avoid all custom and server error from my site.For that I have used Using above code will able avoid some issue . ie.Suppose `` http : //Exaple.com/Careers.aspx '' Page available in my site then Case 1. http : //Exaple.com/Careersss.aspx `` It was working corre... | < customErrors mode= '' RemoteOnly '' defaultRedirect= '' ~/ErrorPage/TryAgainLater.aspx '' > < error redirect= '' ~/ErrorPage/PageNotFound.aspx '' statusCode= '' 404 '' / > < /customErrors > | How to avoid custom/Server error in web site ? |
JS | Based on `` Get selected variation price in jQuery on Woocommerce Variable products '' answer code , in my code bellow , I have a problem with the price calculation of a WooCommerce variable product . The price gets multiplied with 10 or 1000 , depending on the option selected on a dropdown , which is not supposed to h... | < script > jQuery ( function ( $ ) { var jsonData = < ? php echo json_encode ( $ variations_data ) ; ? > , inputVID = 'input.variation_id ' ; $ ( 'input ' ) .change ( function ( ) { if ( `` ! = $ ( inputVID ) .val ( ) ) { var vid = $ ( inputVID ) .val ( ) , // VARIATION ID length = $ ( ' # cfwc-title-field ' ) .val ( )... | Price calculation based on dimensions in WooCommerce single product page |
JS | I use this snippet in Javascript like 100 times a day to have a closure on the enclosing object : it there a way to avoid the Ta variable and still refere to the `` outer '' ( is this word correct ? ) object ? | Class.prototype.Method = function ( arg ) { var Ta = this ; var e = function ( ) { Ta.doSomething ( arg ) ; } ; } ; | How can I avoid using this snippet in Javascript closures ? |
JS | So I am new to express and io but I had a server running fine for webRTC but now there is a deprecated method in webRTC that only runs on https so I tried to create an https server but it starts and then immediately exits . I can not figure out what is wrong and I do not get any errors . Also I am using an aws ec2 to r... | var connect = require ( 'connect ' ) ; var https = require ( 'https ' ) ; var fs = require ( 'fs ' ) ; var express = require ( 'express.io ' ) ; var app = express ( ) ; //app.http ( ) .io ( ) ; var PORT = 443 ; var options = { key : fs.readFileSync ( '../server.key ' ) , cert : fs.readFileSync ( '../server.crt ' ) } ; ... | using https with express io |
JS | Using Bootstrap 4 , I have a < container > that has two columns.On screen sizes that fall within the boostrap 4 breakpoints md-xl , these are arranged in two equally sized columns : col-md-6 , and stack into a single column on sm-xs screens : col-xs-12.I want to move the blue img above the red img on md screens ( so fr... | function movelogo ( ) { var logo = document.getElementById ( 'logo ' ) ; logo.insertBefore ( logo , 'next_col ' ) ; } window.addEventListener ( 'resize ' , movelogo ) ; < ! DOCTYPE html > < html lang= '' en '' > < head > < meta charset= '' UTF-8 '' > < meta http-equiv= '' X-UA-Compatible '' content= '' IE=edge '' > < m... | Move img to a different bootstrap col on breakpoint |
JS | For example I have copied some content/paragraph from wikipedia and then i want to paste code in my webpage dynamically but it 's showing lot of inline styles . I want clean and need proper html format of code . I tried many ways but it 's removing all the tags either i want to remove only extra inline styles and extra... | & amp ; lt ; span style= '' color : rgb ( 34 , 34 , 34 ) ; font-family : sans-serif ; font-size : 14px ; font-style : normal ; font-variant-ligatures : normal ; font-variant-caps : normal ; font-weight : 400 ; '' & amp ; gt ; In 1896 and named after its inventor , & amp ; amp ; nbsp ; & amp ; lt ; /span & amp ; gt ; & ... | How to remove inline styling of copied content from webpage using jQuery ? |
JS | I use private JavaScript class methods in my front-end code and Snowpack for my development workflow.Currently ( as of v2.15.0-pre.5 ) , Snowpack does n't seem to play well with private class methods , i.e. , the following fails to when building with snowpack build : A repo to reproduce is here . After cloning , run : ... | export class TestClass { # test ( ) { console.log ( `` testing ... '' ) ; } test ( ) { this. # test ( ) ; } } npm installnpm run build | JavaScript private class methods with Snowpack |
JS | I can read out text field values , but when I try to find the selected radio button , I get nothing.HTML : What am I doing wrong ? | $ ( document ) .ready ( function ( ) { $ ( `` form # create_form '' ) .submit ( function ( ) { var title = $ ( ' # title ' ) .attr ( 'value ' ) ; var owner = $ ( ' # owner ' ) .attr ( 'value ' ) ; var users = $ ( ' # users ' ) .attr ( 'value ' ) ; var groups = $ ( ' # groups ' ) .attr ( 'value ' ) ; var begin_date = $ ... | Trying to find selected radio button . What 's wrong ? |
JS | Is there any difference in declaring my async javascript statically vs dynamically ? staticdynamicI noticed that declaring a script statically let a browser detect it earlier and preload ( chrome + firefox ) . My goal is to load a javascript in async way in order not to block HTML rendering and other scripts execution ... | < html > < head > ... < /head > < body > ... < div id='my-script-needs-me ' > < /div > < script type= '' text/javascript '' src= '' https : //foo.bar/myscript.js '' async > < /script > ... < /body > < /html > < html > < head > ... < /head > < body > ... < div id='my-script-needs-me ' > < /div > < script type= '' text/j... | Registering an async javascript , declarative ( static ) vs dynamic |
JS | Taking the jQuery framework for example , if you run code like this : The stack trace you get in Firebug will look like this : As you can see , it 's not very readable , because you have to click on each function to find out what it is . The anonymous functions would also show up as ( ? ) ( ) in the profiler , and they... | $ ( document ) .ready ( function init ( ) { foo.bar ( ) ; } ) ; init ( ) anonymous ( ) anonymous ( [ function ( ) , init ( ) , function ( ) , 4 more ... ] , function ( ) , Object name=args ) anonymous ( ) anonymous ( ) var Foo = { bar : function bar ( ) { } } function Foo ( ) { } Foo.prototype.bar = function bar ( ) { ... | Are named functions underrated in JavaScript ? |
JS | So CSS @ media queries do n't work in IE8 . Now , I could create separate CSS files named IE_min768.css and IE_min972_max1024 and use Javascript to dynamically load and unload the files as the page width is adjusted . But that violates D.R.Y . and would be a pain to maintain CSS in multiple places . Would it be possibl... | @ media ( min-width : 768px ) { /* some css */ } @ media ( min-width : 972px ) and ( max-width : 1024px ) { /* different css */ } | Read a CSS file with Javascript and dynamically alter the page |
JS | I would think that all members / objects / etc . documented by JSDoc should be their own click-able links ; e.g. , if I have levelOne -- > levelTwo -- > levelThree -- > levelFour , then I should see levelOne on the first page and be able to click my way through to levelFour ... but that does n't seem to be the case.Her... | /** Contains various tools and extensions . @ namespace App */var app = app || { } ; /**Contains App plugins . @ namespace App.Plugins*/app.Plugins = app.Plugins || { } ; /**Contains methods and classes usable within unit-testing . @ memberof App @ type { object } @ namespace App.UnitTesting*/app.UnitTesting = app.Unit... | JSDoc : Why are n't my nested objects links ( why are n't they click-able ) ? |
JS | I 'd like to implement a string formatter . I 've used formatters that take string like `` the quick , brown { 0 } jumps over the lazy { 1 } '' where you pass in parameters whose cardinal location is used to replace the braced integers.I 'd love to be able to do something more like `` the quick , brown { animal1 } jump... | String.prototype.format = function ( ) { reg = new RegExp ( `` { ( [ ^ { } ] + ) } '' , `` g '' ) ; var m ; var s = this ; while ( ( m = reg.exec ( s ) ) ! == null ) { s = s.replace ( m [ 0 ] , eval ( m [ 1 ] ) ) ; } return s ; } ; | How to implement a string formatter with variable names |
JS | I have the following option text that I want to put into a variable plus remove all characters except the value after the £ then convert it to a number . In this case 28.00This converts the selects options text correctly.But this does n't seem to work with the £ symbol . If i change everything to a $ symbol I have no p... | < option value= '' 294 '' > Set of 2 Boots < /option > < option value= '' 295 '' > Set of 4 Boots [ Add £28.00 ] < /option > recal_var = jQuery ( 'select ' ) .find ( 'option : selected ' ) .text ( ) ; price_result = parseFloat ( recal_var.split ( ' [ Add £ ' ) [ 1 ] .slice ( 0 , -1 ) .replace ( / , /g , '' ) ) ; price_... | remove all characters up to £ and remove last character ] |
JS | Basically , when I call this function , will the xhr object get garbage-collected , or will it stick around forever because the caller is holding on to xhr.responseXML ? If it 's the latter , would this solve it ? Despite all my years of JS , the whole memory-management thing still manages to confuse me ... | function fetchXmlDoc ( uri ) { var xhr = new XMLHttpRequest ( ) ; var async = false ; xhr.open ( `` GET '' , uri , async ) ; xhr.send ( ) ; return xhr.responseXML ; } function fetchXmlDoc2 ( uri ) { var xhr = new XMLHttpRequest ( ) ; var async = false ; xhr.open ( `` GET '' , uri , async ) ; xhr.send ( ) ; var xml = xh... | Will this JavaScript code garbage-collect the way I expect ? |
JS | Say I have a simple function that alerts a message : Now when I call it like so , it does not work . Throws error `` hey is not defined '' But when I call it inside an anonymous function it does work : Why is the `` hey '' variable only visible when I put it inside an anonymous function ? | function callMessage ( msg ) { alert ( msg ) ; } function sayHi ( ) { var hey = `` hi there '' setTimeout ( `` callMessage ( hey ) '' , 1000 ) ; } sayHi ( ) ; function sayHi ( ) { var hey = `` hi there '' setTimeout ( function ( ) { callMessage ( hey ) ; } , 1000 ) ; } sayHi ( ) ; | Why does this closure work ? |
JS | Possible Duplicate : Is there any downside for using a leading double slash to inherit the protocol in a URL ? i.e . src= “ //domain.com ” I have seen the following logic in many places , f.ex the analytics script : But to my knowledge , you could just as well do : and it should use whatever protocol that is currently ... | script.src = ( 'https : ' == document.location.protocol ? 'https ' : 'http ' ) + ' : //example.com/cdn.js ' ; script.src = '//example.com/cdn.js ' ; | Using // instead of prototcol |
JS | Well . I 've got some async code in my Angular component , that works just fine . Looks like this ( briefly ) : I skip some types and name variables a bit awkward ( but simple ) cause it 's not the point . Code works . But I wan na encapsulate process of user 's constructing ( from 2 services ) cause I 'll need it in d... | export class SomeComponent { user : User ; /* ... */ email : string ; /* ... */ private someMethod ( ) : void { /* some code here */ this.userService1.getUsers ( ) .subscribe ( users = > { users.forEach ( user = > { if ( user.email & & user.email === this.email ) { this.userService2.getUser ( user.id ) .subscribe ( fou... | Getting errors trying to get observable from `` observable 's chain '' |
JS | I 'm trying to find a way to remove all the elements ( div 's ) outside of a specific container.For example : I have an HTML container with a few div 's inside of it like so : I basically need to remove all the elements with the class name baby that is outside of container . Some of the elements do n't even have a cont... | < div id= '' container '' > < div class= '' baby '' > < /div > < div class= '' baby '' > < /div > < div class= '' baby '' > < /div > < div class= '' baby '' > < /div > < /div > < div id= '' someID '' > < div class= '' baby '' > < /div > < div class= '' baby '' > < /div > < div class= '' baby '' > < /div > < /div > < di... | Remove all the elements outside of a container ? |
JS | This is the string Option 1|false|Option 2|false|Option 3|false|Option 4|true I want to convert it to array of objects like thisIs This Possible In javaScript Nodejs ? ? ? ? thanks in Advance . | [ { `` option '' : `` Option 1 '' , `` value '' : false } , { `` option '' : `` Option 2 '' , `` value '' : false } , { `` option '' : `` Option 3 '' , `` value '' : false } , { `` option '' : `` Option 4 '' , `` value '' : true } ] | How can I convert string to array of objects in JavaScript |
JS | I need to disable the ability to scroll up on an html page once I get beyond a certain point . I also need a mechanism for returning to the top of said page.I 've tried to accomplish this with the following code , but it has n't worked for me yet because the page is responsive ( thus the point 's location may change wi... | $ ( function ( ) { var scrollPoint = 200 ; var scrolledPast = false ; $ ( window ) .scroll ( function ( ) { $ ( window ) .scrollTop ( ) > scrollPoint ? scrolledPast = true : `` ; $ ( window ) .scrollTop ( ) < scrollPoint & & scrolledPast == true ? $ ( window ) .scrollTop ( scrollPoint ) : `` ; } ) .scroll ( ) ; } ) ; | Disable Scrolling Up After Point on Page |
JS | Let 's say I use the URL interface to create a new URL . E.g . like that : Now I need this as a plain string . How do I best convert it ? Note : The examples here are minimal examples . I obviously do n't convert a ( hardcoded ) string to an URL object and back to a string . To give some context , imagine I modify the ... | new URL ( 'https : //www.example.com/démonstration.html ? query=6 # bla ' ) ( new URL ( 'https : //www.example.com/démonstration.html ? query=6 # bla ' ) ) .href// `` https : //www.example.com/d % C3 % A9monstration.html ? query=6 # bla '' ( new URL ( 'https : //www.example.com/démonstration.html ? query=6 # bla ' ) ) ... | What is the difference between href and toString when converting an URL interface to string ? |
JS | When I use only this route with my all other routes , that static files served well : But when I add below these lines - all requests are catch with this router ( not the previous one ) : It 's strange to me , because /public definition comes first . But all request goes to last defined /* request handler.Now , if I tr... | var public_dir = path.join ( __dirname , 'public ' ) ; app.use ( '/public ' , express.static ( public_dir ) ) ; app.get ( '/* ' , function ( req , res ) { res.redirect ( '/ # ! ' + req.path ) ; } ) ; app.use ( app.router ) ; | Node.js / Expess.js . Static router not recognized if used with wildcard router |
JS | When accessing elements by window.someThing , the `` someThing '' should be the name of html element . But what I see now , is that I can access an element by id in the same way , without document.getElementById . When has this been changed ? It looks like it works in Chrome , IE , Firefox 13 , but not in Firefox 12.Fo... | < div id= '' MyDiv '' > Content < /div > < script > MyDiv.innerHTML = `` New Content '' ; < /script > var MyDiv = document.getElementById ( 'MyDiv ' ) ; | Is getElementById optional in some browsers ? |
JS | NOTE : I have no problem using setAttribute in my project . This is merely a question as to why something is not working.I have made a basic .js , .html and .css file . Here is the code for each : I have commented out setAttribute because it works , but when I try to use .style.margin it does n't work . There are no er... | //Load Documentwindow.onload = ( ) = > { //get Body Height and Width let body = document.body ; let html = document.documentElement ; let bH = Math.max ( body.offsetHeight , body.scrollHeight , body.clientHeight , html.offsetHeight , html.scrollHeight , html.clientHeight ) ; let bW = Math.max ( body.offsetWidth , body.... | JavaScript : setAttribute works but .style does n't |
JS | In one of our tests , we have the following set of expectations : On one hand , having multiple simple expectations provide a more precise and understandable feedback , but , on another , this looks like it violates the DRY principle and the `` one expectation per test '' commonly acceptable guideline.Is there a way to... | expect ( headerPage.dashboard.isDisplayed ( ) ) .toBe ( true ) ; expect ( headerPage.queue.isDisplayed ( ) ) .toBe ( true ) ; expect ( headerPage.claimSearch.isDisplayed ( ) ) .toBe ( true ) ; expect ( headerPage.claim.isDisplayed ( ) ) .toBe ( true ) ; expect ( headerPage.case.isDisplayed ( ) ) .toBe ( true ) ; expect... | Simplifying multiple boolean checks into a single one |
JS | I have parsed a given CSS file/string into a JSON object like so : What I want to do now is re-order them based on Specificty . In this case , the # header h1 should come after the h1 in the JSON object as this is how they 'll be applied in the browser.How can I do this ? Are there any existing libraries for this ? Or ... | { `` # header '' : { `` color '' : `` # 000000 '' } , `` # header h1 '' : { `` color '' : `` # 000 '' } , `` h1 '' : { `` color '' : `` # 4fb6e5 '' } } | Order CSS based on Selector Specificity |
JS | I want to make 3 div side by side where each can expand to full screen when click a button while collapsing the other ( but still show the title with vertical orientation ) . Something like CodePen did . Here is what it looks like in their page.Initially it shows 3 equal size div side by side . And when you double clic... | < div class= '' editor-resizer html-editor-resizer '' title= '' Double-click to expand . `` > < /div > < div id= '' box-html '' class= '' box box-html '' data-type= '' html '' > < div class= '' powers '' > < div class= '' powers-drag-handle '' title= '' Double-click to expand . `` > < /div > < div class= '' editor-acti... | Resizer to expand and minimize div |
JS | I have two directives in Angular . One has to be trascluded in the other . My problem is that I ca n't access the DOM with simple JQuery selector after the transclude function has run . In particular I want to compile the first directive ( topic ) and then inject it in the other one ( about-us ) so I can access the DOM... | < section > < topic active = `` true '' title = `` Lorem ipsum '' icon = `` ti-layers '' > A ) Lorem ipsum dolor sit amet , consectetur adipisicing elit , sed do eiusmod tempor incididunt ut labore et dolore magna aliqua . Ut enim ad minim veniam , quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo... | Link function after transclude in Angular js |
JS | So i have couple of spans within a div and most of them have classes or other attributes.I would like to select the very first span that has no attributes but also make sure that the last span that has no attributes wont be selected.Also , the element with class one will sometimes appear and sometimes wont so i ca n't ... | < span class= '' one '' attribute= '' test '' > < /span > < span > < /span > /* This is what i need to select */ < span class= '' three '' attribute= '' test '' > < /span > < span class= '' four '' attribute= '' test '' > < /span > < span > < /span > | How to select an element that has no attributes |
JS | I have installed the Resharper extension to visual studio.When i implement the code like below in JavaScriptit suggest me to normalise the local declaration , it will change code to like belowHowever both code snippet is work well , Is it important to normalize local declaration ? . will it influence page loading perfo... | updateTable ( ) ; function updateTable ( ) { //code here } function updateTable ( ) { //code here } updateTable ( ) ; | Is it important to normalize local declaration in javascript |
JS | Because jQuery is a widely used and mature collaborative effort , I ca n't help but to look at its source for guidance in writing better Javascript . I use the jQuery library all the time along with my PHP applications , but when I look under the hood of this rather sophisticated library I realize just how much I still... | $ ( ' # element ' ) .attr ( 'alt ' , 'Ivan is SUPER hungry ! lolz ' ) ; $ ( ' # element ' ) .attr ( { 'alt ' : 'Ivan is an ugly monster ! omfgz ' } ) ; ( function ( window , undefined ) { /* jQuery */ } ) ( window ) ; $ ( ' # element ' ) .attr ( 'alt ' , 'Adopt a Phantom Cougar from Your Local ASPCA ' ) ; function $ ( ... | Better Understanding Javascript by Examining jQuery Elements |
JS | If there is a constructor likethenBut on the other hand , results inSo what I was thinking is thatwould result in the same thing . However , when returning a Number , How is this possible ? Why ca n't I make a constructor return something else than an Object ? ( I do know making a constructor returning a Number is rath... | function a ( ) { } ( new a ) instanceof a === true function a ( ) { return { } } ( new a ) instanceof a === false function a ( ) { return 123 } ( new a ) instanceof a === true | Why can a constructor only return an object ? |
JS | I 'm programming snake with Javascript . For the background of the different body parts I 'm using the following gradient generation : My problem is that when the snake moves and it changes directions , the gradient needs to be bent to fit in the last body part before the corner ends and the last that follows the strai... | gibGradient : function ( ) { var string = `` background : linear-gradient ( to right , rgba ( 243,226,199,1 ) 15 % , rgba ( 193,158,103,1 ) `` + snake.data.gradientLinks + '' % , rgba ( 182,141,76,1 ) `` + snake.data.gradientRechts + '' % , rgba ( 233,212,179,1 ) 90 % ) ; '' ; if ( ( snake.data.gradientLinks < 85 ) & &... | How to create a bent gradient ? |
JS | I am preparing externs file for pixijs library to work with closure compiler.The only problem I am having so far is with custom object parameters . Here is a short example : pixi.js source : closure compiler output : How can these pixijs annotations be adapted to closure compiler annotations ? If there is no way to ach... | /** * Set the style of the text * * @ param [ style ] { object } The style parameters * @ param [ style.font='bold 20pt Arial ' ] { string } The style and size of the font * @ param [ style.fill='black ' ] { string|number } A canvas fillstyle that will be used on the text eg 'red ' , ' # 00FF00 ' * @ param [ style.alig... | Closure Compiler EXTERNS for PIXI.js - custom object parameter annotations |
JS | I 'm looking for the best way to update in object instance , for the example in this case myParentObjects 's name property . The only way I understand to achieve this would be to pass reference of the parent object to the child object instance as a parameter into either new myChildObj ( this , name ) in the constructor... | function myParentObj ( ) { this.name = 'jordan ' this.names = [ 'jordan ' , 'danny ' , 'cassie ' ] ; this.init= ( ) = > { this.names.forEach ( ( name ) = > { var childObj = new myChildObj ( this , name ) ; childObj.updateParentProperty ( ) ; } ) } } function myChildObj ( parentObj , name ) { this.parent = parentObj ; t... | Update an instance 's property , from another instance |
JS | Curly braces in JavaScript regex is used to denote quantifiers . So writingwill match aa , aaa and aaaa . But if you mistype this quantifier like this : It will match the literal text `` x { 1 , x } '' , at least in Firefox.Is this behavior common to modern browsers ? The ECMA standard prohibits this behavior and requi... | a { 2,4 } x { 1 , x } | Is handling of curly braces in javascript regex is the same across all modern browsers ? |
JS | I 'm trying to connect Chrome extension and my C # application.I 'm using this code https : //stackoverflow.com/a/13953481/3828636Everything is almost working there in only one problem I can send message only 6 times and than my c # app does n't recieve anything . When I re-open my extension ( click on icon ) it works ... | function send ( data ) { var data = new FormData ( ) ; var xhr = new XMLHttpRequest ( ) ; xhr.open ( 'POST ' , listener , true ) ; xhr.onload = function ( ) { } ; xhr.send ( data ) ; } | Communication JQuery and C # |
JS | I have a HTML snippet which looks like this : Since most users do not care for the details , I would like to hide the traceback and only show the first few characters.The remaining text should only be visible if you expand the text.This should be visible as hyperlink : `` Traceback ... . '' How to do this with ? ( I ca... | < pre > Traceback ( most recent call last ) : File `` /home/foobar_cok_p/src/foobar/foobar/models/job.py '' , line 69 , in execute_job_and_create_log output = self._execute_job_and_create_log ( ) File `` /home/foobar_cok_p/src/foobar/foobar/models/job.py '' , line 127 , in _execute_job_and_create_log return self.execut... | Show first ten characters , expand on click ( or hover ) |
JS | The book `` JavaScript : The Definative Guide , 6th edition '' in section 4.13.5 states that -But when I display the value like this -orThe value 0 is displayed . I experimented , and whatever the value of i is set to , is displayed.The book seems to be wrong . Can anyone explain what the book meant by saying the state... | `` i=0 , j=1 , k=2 ; evaluates to 2 '' var x = i=0 , j=1 , k=2 ; alert ( x ) ; alert ( i=0 , j=1 , k=2 ) ; | JavaScript comma and variable evaluation |
JS | I am trying to emulate Chrome 's native messaging feature using Firefox 's add-on SDK . Specifically , I 'm using the child_process module along with the emit method to communicate with a python child process.I am able to successfully send messages to the child process , but I am having trouble getting messages sent ba... | var utf8 = new TextEncoder ( `` utf-8 '' ) .encode ( message ) ; var latin = new TextDecoder ( `` latin1 '' ) .decode ( utf8 ) ; emit ( childProcess.stdin , `` data '' , new TextDecoder ( `` latin1 '' ) .decode ( new Uint32Array ( [ utf8.length ] ) ) ) ; emit ( childProcess.stdin , `` data '' , latin ) ; emit ( childPr... | How to message child process in Firefox add-on like Chrome native messaging |
JS | On page 90 of Crockford 's JavaScript : The Good Parts , he has code has the following : Is there a good reason for the closure and immediately invoked outer function ? The following seems to work just as well : | String.method ( 'entityify ' , function ( ) { var character = { ' < ' : ' & lt ; ' , ' > ' : ' & gt ; ' , ' & ' : ' & amp ; ' , ' '' ' : ' & quot ; ' } ; return function ( ) { return this.replace ( / [ < > & '' ] /g , function ( c ) { return character [ c ] ; } ) ; } ; } ( ) ) ; console.log ( `` < & > '' .entityify ( )... | Crockford 's entityify method -why the closure ? |
JS | I want to find values less than a certain value in the array.I tried to use Number.EPSILON because the input value is not a definite value ( eg 1.5000000000001 ) .I found something strange during the test : Why is this ? The test environment is the Chrome browser console . | > > ( 1.5 < 1.5 + Number.EPSILON ) < - true > > ( 2.5 < 2.5 + Number.EPSILON ) < - false | Why is `` ( 2.5 < 2.5 + Number.EPSILON ) '' false in JavaScript ? |
JS | most javascript libraries contain lines similar to : if a is null , what is ( 0 ) .documentElement supposed to return ? | var b = ( a ? a.ownerDocument || a : 0 ) .documentElement ; | what does getting the documentElement of 0 return |
JS | I have an object , I want to send this object 's simplified version to the server.I have two question : :1 ) Is it possible to extract something like this with replacer parameter of JSON.stringify ( ) ? 2 ) At least can I extract something like this with replacer parameter of JSON.stringify ( ) ? When I am using like t... | { `` fullName '' : `` Don Corleone '' , `` actor '' : { `` actorId '' : 2 , `` name '' : `` Marlon '' , `` surname '' : `` Brando '' , `` description '' : `` Marlon Brando is widely considered the greatest movie actor of all time ... `` , `` heroList '' : [ ] , `` photo '' : `` C : \\projects\\files\\actor\\15329553769... | JSON.Stringfy method 's replacer argument not working on nested object |
JS | I have a text input , that presently goes transparent when a user presses shift ( keydown ) and binds a listener for the shift key going upie.This works fine when no characters are pressed in the interim between depressing and releasing the shift key . The problem is that when shift is down and another character is pre... | $ ( ' # foo ' ) .keydown ( function ( ) { if ( event.which==16 ) { //make # foo transparent $ ( this ) .keyup ( function ( ) { if ( event.which==16 ) { //return # foo to its former glory $ ( this ) .unbind ( 'keyup ' ) ; } } ) ; } ; } ) | the shift key is just ignored after another key has been depressed , poor shift key . How do I detect when it is released ? |
JS | I got hold of some obfuscated JavaScript code . I tried to understand it , and doing this , I typed pieces of it in the console . I ca n't understand whyWhy is ( ( ! ! + [ ] + '' '' ) [ + ! ! [ ] ] ) equal to `` a '' in JavaScript ? Is there some other code snippets to get others letters ? I guess it 's something to do... | > ( ( ! ! + [ ] + '' '' ) [ + ! ! [ ] ] ) < `` a '' | Why is this expression evaluated to `` a '' in JavaScript ? |
JS | I have a script that translates a Russian forum word by word using TreeWalker , but there are one kind of div element that I could n't change its text and that 's my question , how do I change that ? As the forum requires registration I 'm going to try to provide every detail of code I can below.the webpage specific co... | < div class= '' sp-wrap '' > < div class= '' sp-head folded clickable '' > Скриншоты < /div > //once clicked unhide the div below to show images and by clicking it again hides . < div class= '' sp-body inited '' title= '' '' style= '' display : none ; '' > //hidden div < div class= '' clear '' > < /div > < h3 class= ''... | Unable to change text from a div |
JS | I have developed some sort of Jcrop initialization for a website , I managed to make my own namespace . Question I have is regarding this keyword . Every time I had to access my base object `` aps '' in any callback function I must wrap this in a variable ( I have chosen word that ) . Is there any better way to do it ?... | var aps ; $ ( function ( ) { aps = function ( ) { // private // variables var bgColor = ' # f5f5f5 ' ; var threshold = 370 ; var threshold_width = 800 ; return { tmpl : $ ( ' # jcrop-template ' ) .html ( ) , upl_cont : { } , form : { } , logo_img : new Image ( ) , jcrop_api : null , scaled_logo_url : `` , image_filenam... | how to call 'this ' outside my objects scope ? |
JS | I want to recreate the circular scrollbox as depicted in the GIF below , I do n't think there is some why if making a circular scrollbox using css is possible so I thought of adding padding-left to each child of the ul to make the scrollbox appear circular.To achieve this , add padding of 0px to li-1add padding of 2px ... | var scrollBox = $ ( `` .circularScrollbox '' ) , num = $ ( `` .scrollboxList li '' ) .length , vjListItem = $ ( `` .vjListItem '' ) , max = num * 3 , padding = 0 , currentPadding = padding , scrollPos = scrollBox.scrollTop ( ) ; scrollBox.scroll ( function ( ) { if ( scrollPos < scrollBox.scrollTop ( ) & & currentPaddi... | How to make a circular ScrollBox using JavaScript/CSS ? |
JS | There is a problem with that animation I found here : jQuery animated number counter from zero to valueHere is the problem , I used it on test website and the counter do n't go on the exact value when it 's with big numbers.here 's the HTML : here 's the javascript : http : //jsfiddle.net/Yy6r6/68/Do someone have an id... | < span class= '' Count '' > 66620 < /span > < br/ > < span class= '' Count '' > 66666666 < /span > < br/ > < span class= '' Count '' > 66666666 < /span > $ ( '.Count ' ) .each ( function ( ) { var $ this = $ ( this ) ; jQuery ( { Counter : 0 } ) .animate ( { Counter : $ this.text ( ) } , { duration : 1000 , easing : 's... | Jquery animation number from to |
JS | SITUATION : I currently load the latest posts chronologically with this code : CODE : QUESTION : How should I modify it to essentially have the exact same behaviour but to only query posts with scores above 100 according to their chronological order ? UPDATE : I have finally found a way to use the `` create another ind... | $ scope.data = [ ] ; var _n = Math.ceil ( ( $ ( window ) .height ( ) - 50 ) / ( 350 ) ) + 1 ; var _start = < % = lastID % > ; var firstElementsLoaded = false ; $ scope.getDataset = function ( ) { fb.orderByChild ( 'id ' ) .startAt ( _start ) .limitToFirst ( _n ) .on ( `` child_added '' , function ( dataSnapshot ) { _st... | How to load the latest posts with score above 100 ? |
JS | I saw a tutorial for JavaScript ES6 in which the guy used this syntax to assign a value with let : What is the difference between the first and this : | let = name = [ 'Jhon ' , 'Paul ' , 'Ean ' ] let name = [ 'Jhon ' , 'Paul ' , 'Ean ' ] | Different forms of using 'let ' |
JS | Suppose I have a service that retrieves a list of tags and I store tags in the cache : What is the common approach to invalidate the cache ? Should I compare it to current date ? Does angular provide any mechanism of cache invalidation ? And what 's the benefit of using cacheFactory instead of a variable holding cache ... | function TagsRetriever ( ) { var cache = $ cacheFactory ( `` tags '' ) ; function getTags ( ) { var cached = cache.get ( `` tags '' ) ; if ( cached ) { return cached ; } else { return $ http.get ( `` url/getTags '' ) .then ( function ( tags ) { cache.put ( `` tags '' , tags ) ; } ) ; } } } | what 's the common approach for caching data in angular.js |
JS | I have a coordinate system which basically represents a screen.And I have an arbitrary amount of positions . E.g . : I 'm looking for an algorithm that finds the most unpopulated point . The white mini circles represent the population and the red Xs mark points that appear very unpopulated to me : My goal is run an ani... | population = [ { x : 100.44 , 200.54 } , { x : 123.45 , 678.9 } , { x : 1300.23 , 435.81 } , { x : 462.23 , 468.37 } , { x : 956.58 , 385.38 } , ] ; let circles = [ { x : 60.44 , y : 190.54 } , { x : 103.45 , y : 18.9 } , { x : 390.23 , y : 135.81 } , { x : 302.23 , y : 28.37 } , { x : 56.58 , y : 85.38 } , ] function ... | Find most unpopulated points in a coordinate system |
JS | What is the best way to put javascript/html/css code in the maven repository , so that is easily usable by java projects.Is there a way to do it such that the included project can be easily made `` web-visible '' by the including project ? For example assume I write a very useful tricks.js file an put it in the mvn rep... | < script src= '' /some/thing/tricks.js '' / > | best practice : how to host server-side code in the maven repository |
JS | Place holder is not working in IE-9 , so I used the below code for place holder.When I am taking the value of test , it shows null.How can I get the details of all input tag ? | jQuery ( function ( ) { debugger ; jQuery.support.placeholder = false ; test = document.createElement ( 'input ' ) ; if ( 'placeholder ' in test ) jQuery.support.placeholder = true ; } ) ; // This adds placeholder support to browsers that would n't otherwise support it . $ ( function ( ) { if ( ! $ .support.placeholder... | Place holder is not working |
JS | I 'm a student of Computer science and we are making exercises on javascript the exercises was : '' Replace item number 4 by a new item with id `` numberFour '' and with text `` Mistreatment '' . '' this is how it looked before i made the exercise : Number one : Looking For a MateNumber two : BoredomNumber three : Lack... | var vier = document.createElement ( `` li '' ) ; vier.innerHTML = `` Number four : Mistreatment '' ; vier.setAttribute ( `` id '' , `` numberFour '' ) ; var lijst = document.querySelector ( `` # fiveReasons '' ) ; lijst.replaceChild ( vier , lijst.childNodes [ 3 ] ) ; var vier = document.createElement ( `` li '' ) ; vi... | javascript replaceChild does n't work |
JS | In JavaScript , what 's the difference betweenand ? | var x = Object ( ) ; var x = new Object ( ) ; | How do `` Object ( ) '' and `` new Object ( ) '' differ in JavaScript ? |
JS | In my code I have a line that dumps the current window ( which happens to be a youtube video page ) : It can be seen that window object contains `` yt '' property , which is another object that can be easily inspected in debugger : http : //i.imgur.com/lHHns.pngUnfortunately , callinglogs `` undefined '' - why is that ... | Firebug.Console.log ( myWindow ) ; Firebug.Console.log ( myWindow.yt ) ; | JavaScript objects visible in FireBug , inaccessible in code |
JS | I 'm using JavaScript 's Math.random ( ) function to distribute items over buckets.Afterwards , I display the buckets in a canvas . I would expect the items to be distributed evenly , but ( even after multiple retries in multiple browsers ) , it seems like the distribution is much more fine grained on the left ( closer... | < html > < head > < script > window.onload = function ( ) { var canvas = document.getElementById ( 'canvas ' ) ; var ctx = canvas.getContext ( '2d ' ) ; var width = canvas.width ; var height = canvas.height ; var buckets = width ; var total = width*height*0.3 ; var bucketList = [ ] ; // initialized each bucket to 0 ite... | Javascript weird random behavior |
JS | I 've seen the following ( bizarre ) Javascript rounding function in some legacy code . After googling for it I can see that it crops up in a number of places online . However I ca n't work out why the hard-coded values 8191 and 10485 are present.Does anyone know if there 's any sensible reason why these values are inc... | function roundNumber ( num , dec ) { var newnumber = 0 ; if ( num > 8191 & & num < 10485 ) { num = num-5000 ; newnumber = Math.round ( num*Math.pow ( 10 , dec ) ) /Math.pow ( 10 , dec ) ; newnumber = newnumber+5000 ; } else { newnumber = Math.round ( num*Math.pow ( 10 , dec ) ) /Math.pow ( 10 , dec ) ; } return newnumb... | Hard-coded 8191 10485 values in JavaScript rounding function |
JS | I 've made this snippet using ramda to check if any value of array A exists in array B , assuming they are flat arrays.What I do not like is that hardcoded beta inside valueOfArrayInArray . Can it be done differently so that it 's not ? Please note that I 'm not looking for a completely different implementation that ha... | var hasAtLeastOneTruthValue = ramda.contains ( true ) ; var alpha = [ 1,2,3 ] var beta = [ 4,1,7 ] ; var valueOfArrayInArray = ramda.map ( function ( a_v ) { return ramda.contains ( a_v , beta ) ; } ) ; console.log ( hasAtLeastOneTruthValue ( valueOfArrayInArray ( alpha ) ) ) ; | Can I curry this better ? |
JS | I do n't know how to find the place part ( one of 4 triangles ) of a cursor in a rectangle.This image is more efficient than my explication : sIm in javascript ( so the rectangle is a DIV , 0,0 placed ) I have those varaibles : I just want to know mathematically where is the cursor , in the triangle 1 , 2 , 3 or 4thx | var cursor_x = e.clientX + $ ( document ) .scrollLeft ( ) var cursor_y = e.clientY + $ ( document ) .scrollTop ( ) var rect_w = $ ( rectangle ) .width ( ) var rect_h = $ ( rectangle ) .height ( ) | Find the place of a cursor in rectangle |
JS | I have several divs arranged vertically one on top of the other which from here on out I will call panels . Each panel has the width and height of the viewport . All panels have the same background color at all times . Initially , that color is black.Every other panel is empty , and acts as a gap between panels that ac... | $ ( document ) .scroll ( function ( ) { var viewportHeight = $ ( `` html '' ) .outerHeight ( ) ; var currentY = $ ( document ) .scrollTop ( ) ; if ( currentY % viewportHeight ! = 0 ) { lighten ( ) ; } else { darken ( ) ; } } ) ; function darken ( ) { $ ( `` body '' ) .css ( `` background-color '' , `` black '' ) ; $ ( ... | Change color when user has scrolled down enough and then back |
JS | Anyone can explain me , why local Regex variable and non local Regex variable have different output.I have created a JSFiddle for the same here . | var regex1 = /a|b/g ; function isAB1 ( ) { return regex1.test ( ' a ' ) ; } console.log ( isAB1 ( ) ) ; // trueconsole.log ( isAB1 ( ) ) ; // falseconsole.log ( isAB1 ( ) ) ; // trueconsole.log ( isAB1 ( ) ) ; // falsefunction isAB2 ( ) { var regex2 = /a|b/g ; return regex2.test ( ' a ' ) ; } console.log ( isAB2 ( ) ) ... | Regex.test ( ) is giving true false sequential ? |
JS | I have an array of dynamic objects like that : How can I get just the unique objects ? The desired output is an array containing just the unique objects : I 'm trying something like that using reduce , but on this way I need know the object key : It 's not a duplicate because the other questions does not use `` dynamic... | var arr = [ { state : `` FL '' } , { state : `` NY '' } , { state : `` FL '' } , { gender : `` Male '' } , { state : `` NY '' } , { gender : `` Female '' } , { gender : `` Female '' } , { year : `` 1990 '' } ] arr = [ { state : `` FL '' } , { state : `` NY '' } , { gender : `` Male '' } , { gender : `` Female '' } , { ... | Get unique values from array of objects |
JS | I would like to place links inside of a block that would look like a code block.I believe it 's impossible to do it in a real code block ( though it 'd be nice ) , but I do n't really need it as I do n't need nor the evaluation nor the syntax highlighting ( so please do n't mark as duplicate of a post that asks for fun... | `` ` { r , echo=TRUE , eval=FALSE } [ print ] ( # print ) ( `` hello world '' ) `` ` # # # print { # print } print prints its argument and returns it invisibly ( via invisible ( x ) ) . -- -title : `` Untitled '' output : html_document -- - `` ` { r , eval = FALSE } mod < - lm ( mpg ~ hp , data = mtcars ) summary ( lm ... | have internal links into code looking blocks |
JS | I have four images inside class box having id box1 , box2 , box3 and box4..each image can be dragged and dropped to rectangle below..my problem is when i try to position it on the dropped area using nth child in css it is not workingwhere is the mistake happenining in css ? How to position images on dropped area using ... | function allowDrop ( ev ) { ev.preventDefault ( ) ; } function drag ( ev ) { ev.dataTransfer.setData ( `` text '' , ev.target.id ) ; } function drop ( ev ) { ev.preventDefault ( ) ; var data = ev.dataTransfer.getData ( `` text '' ) ; console.log ( data ) ; $ ( `` # '' +data ) .css ( `` position '' , '' unset '' ) ; ev.... | How to position images on dropped area using nth child in javascript |
JS | I 'm getting crazy . What 's wrong this hello-worldesque example ? I 'm trying just to test some basic things with angularjs 1.5.5.HTML : JS : JsFiddle : http : //jsfiddle.net/d3v6vq7w/7/Simpy put , the loop works with 1 iterations , but not with for example 2 . Nothing gets printed . What gives ? | < div ng-app= '' myApp '' ng-controller= '' Ctrl '' > < h3 > test 1 : < /h3 > < span ng-repeat= '' label in test ( 1 ) '' > { { label } } < /span > < h3 > test 2 : < /h3 > < span ng-repeat= '' label in test ( 2 ) '' > { { label } } < /span > < /div > angular.module ( 'myApp ' , [ ] ) .controller ( 'Ctrl ' , [ ' $ scope... | ng-repeat , for-loop and push |
JS | I know that to debug content script use normal web developer tools ( https : //developer.mozilla.org/en/docs/Mozilla/Add-ons/WebExtensions/Debugging # Debugging_content_scripts ) , and this works perfect . debugger keyword works as intended.But in this exact situation things get broken : What we would expect , that in ... | addon.id = `` 123-568-485 '' ; // I never define ` addon ` before this line , so this cause : ReferenceError : `` addon is not defined '' . We are n't aware of this mistake.// Some more code// Some more code// Some more code// Some more codedebugger ; // Here we want to stop execution and inspect , some other stuff . R... | Console does n't log js errors from content script |
JS | So I 've got this JS code here , and I 'm trying to set obj from the success and error callbacks , but apparently the toLinkInfo function scope is not a parent scope of those ? I always get null back from this function no matter what . I tried a bunch of stuff but could n't get it to work , I guess I 'm too used to C &... | LinkInfoGrabber.prototype.toLinkInfo = function ( ) { var obj = null ; $ .ajax ( { url : this.getRequestUrl ( ) , success : function ( raw ) { obj = new LinkInfo ( raw ) ; } , error : function ( jqXHR , textStatus , errorThrown ) { obj = new LinkInfoException ( jqXHR , textStatus , errorThrown ) ; } , dataType : 'html ... | Accessing outer scope in JavaScript |
JS | Wanted to make a generic cascading dropdown but am weak in recursionThe code is supposed to end up with One select for items - clothes or gadgets - when a choice is madeOne select with either Levis/Gucci or LG/Apple - when a choice is madeOne select with either Levis jeans or jackets or Gucci shoes or dresses - when a ... | const selObject = { `` -- Select Item -- '' : { `` Clothes '' : { `` -- Select brands -- '' : { `` Levis '' : { `` -- Select product -- '' : { `` Jeans '' : { `` -- Select size -- '' : [ `` 38 '' , `` 39 '' , `` 40 '' ] } , `` Jackets '' : { `` -- Select size -- '' : [ `` 41 '' , `` 42 '' , `` 43 '' ] } } } , // end Le... | Plain JS Cascading selects of unknown depth |
JS | I am using leafletjs for my test app . I need to fire the zoomout event when the browser is resized.Here is my browser resize code : This code if to show the map : What I have done is create a global variable called mapOptions . First the map is initialized with mapOptions.zoom = 7 and when the browser is resized , the... | ( function ( ) { $ ( window ) .on ( `` resize '' , resize ) ; function resize ( ) { `` use strict '' ; if ( $ ( window ) .width ( ) < = 765 ) { mapOptions.zoom = 5 ; console.log ( mapOptions.zoom ) ; } } } ) ( ) ; L.TopoJSON = L.GeoJSON.extend ( { addData : function ( jsonData ) { if ( jsonData.type === `` Topology '' ... | How can I fire a zoom out event in browser resize ? |
JS | the problemthis works fine : but this does n't : obs : the functions are wrapped in a $ ( document ) .ready event.the outputsworking : not working : | $ ( ' # edit_curriculum .generated ' ) .children ( ) .blur ( function ( ) { console.log ( this ) ; } ) ; $ ( ' # edit_curriculum .generated ' ) .children ( ) .live ( 'blur ' , function ( ) { console.log ( this ) ; } ) ; < input type= '' text '' name= '' phones [ ] '' class= '' medium phone valid '' > Uncaught Synt... | problem with jquery 's `` live '' function |
JS | I 'm using Sencha 2.3.0 and I want to have a XTemplate side-to-side to a component ( textfield ) on a ListItem . The code above works fine for DataView/DataItem , but I want to use the grouped property that is only available on List/ListItem.The nested Xtemplate gets rendered fine as DataItem . How can I make it work f... | Ext.define ( 'app.view.myList ' , { //extend : 'Ext.dataview.DataView ' , extend : 'Ext.dataview.List ' , xtype : 'mylist ' , requires : [ 'app.view.MyItem ' ] , config : { title : `` myTitle '' , cls : 'mylist ' , defaultType : 'myitem ' , grouped : true , store : 'myStore ' , useComponents : true , itemCls : 'myitem ... | XTemplate definition on items property of a ListItem |
JS | I 'm making a slideshow-type rotator for a website I 'm making . The rotator itself works fine , but I 'm trying to make the slideshow slide forward/back with the left/right keys on the keyboard . My code is this : My code works fine , but only once . I can rotate left once or right once , but after I do , I ca n't re-... | $ ( document ) .keydown ( function ( e ) { var currentPosition = 0 ; var slideWidth = 836 ; var slides = $ ( '.slide ' ) ; var numberOfSlides = slides.length ; var animLength = 600 ; if ( e.keyCode == 37 ) { currentPosition = currentPosition-1 ; // Check to see if new position is unbounded , and wrap accordingly . chec... | Javascript button listener fires once ? |
JS | As I 've gotten to know JS better , I 've moved from a procedural style to semi-OO ( do n't ask me what I mean by that : a mess basically ! ) but now I want to start using it properly . OO appeals to my coding-brain.However , I 'm trying to develop a library of school weeks , and I 'm not sure how I 'd best go about it... | WeeksArray [ 36 ] .StartDate = `` 2011-09-05 '' ; WeeksArray [ 36 ] .EndDateSchool = `` 2011-09-09 '' ; WeeksArray [ 36 ] .EndDateProper = `` 2011-09-11 '' ; WeeksArray [ 36 ] .JSDate = new Date ( 2011 , 8 , 05 ) ; WeeksArray [ 36 ] .Type = `` 1 '' ; WeeksArray [ 36 ] .Label = `` Week 36 : 5th Sept 2011 '' ; var LEAP =... | Object Oriented JavaScript : How would you go about this ? |
JS | I have a dataset with a column called CategoryLevel1 which contains the names of groups . I applied the nest function to Categorylevel1 and generated a series of svgs based on the keys . I then created rectangles representing items in the entire dataset and repeated the rectangles in each svg . I applied a filter to ea... | var doc = ` Manual Name CategoryLevel1 CategoryLevel2DOG `` General Furry , Program and Subject Files '' Average Quantity and Planning EdiblesTR Senate Committee on animal Standards Bowl and Plate Design EdiblesTR Published Canine Bowl and Plate Design EdiblesTR Canine case files Bowl and Plate Design EdiblesDOG Canine... | How do I position subgroups of small multiples together on the page ? |
JS | component.jsthen in the htmlThe reason I ask is I have seen it by example and thought it made sense , but is their any reading on why this is good practice ? is this Object-Oriented Javascript ? if this IS OO javascript , does this pattern make prototypal definitions useless ? Good answer to above questionJavascript : ... | var component = ( function ( ) { var self ; var default_options = { array_option : [ ] , string_option : `` default '' } ; return { other_function : function ( args ) { } , init : function ( options ) { self = this ; // merge in user options for ( var attr in options ) { if ( options.hasOwnProperty ( attr ) ) { self.o ... | What is this pattern called in Javascript ? does it have a name ? |
JS | Here are 2 javascript functionsAnd another code is thisIn both function assignment/declaration is after alert ( ) call.Then why alert message are 10 and undefined respectively ? | var a = 10 ; function abcd ( ) { alert ( a ) ; //alerts 10 a=5 ; } var a = 10 ; function abcd ( ) { alert ( a ) ; //alerts undefined var a=5 ; } | javascript variable scope in function confusion |
JS | I 'm wondering if the texture to my sphere is somehow not being applied correctly , and if I can offset it somehow ? I am trying to place a box at Sydney , Australia by supplying the lat/lon and converting to cartesian xyz coordinates . However , the box is not places in the correct location . My guess is since the ori... | var img ; var theta = 0 ; var r = 400 ; function preload ( ) { img = loadImage ( 'https : //eoimages.gsfc.nasa.gov/images/imagerecords/79000/79765/dnb_land_ocean_ice.2012.3600x1800.jpg ' ) ; } function setup ( ) { createCanvas ( 1600 , 1200 , WEBGL ) ; } function draw ( ) { background ( 0 ) ; rotateY ( theta ) ; theta ... | Texture on sphere not aligned correctly ? Lat/Lon - > Cartesian xyz |
JS | So void returns undefined after executing the expression passed to it . undefined throws exceptions when you try to access its properties . So why is that void ( 0 ) .prop returns undefined instead of crashing ? http : //jsfiddle.net/bFhLS/ | alert ( `` void ( 0 ) = > `` + void ( 0 ) ) ; // undefined// How is it that this does n't throw an exception ? alert ( `` void ( 0 ) .someprop = > `` + void ( 0 ) .someprop ) ; // undefined// Exception , ca n't access property of undefined.alert ( `` undefined.someprop = > `` + undefined.someprop ) ; // crash | void ( 0 ) returns ` undefined ` , but allows property access . Why ? |
JS | I 've seen this pretty funny screencast yesterday about some oddities in languages like Ruby and Javascript and the guy shows that : not very obvious ... I 've decided to go to the ECMAscript language specification to get more info . I 've started with the + operator implementation ( p.75 ) which says : 11.6.1 The Addi... | [ ] + [ ] - > `` '' // returns empty string [ ] + { } - > [ object Object ] { } + [ ] - > 0 | Why Array + Array equals empty string ? |
JS | I have two modules , both of which need to access a shared array . I solve this by having a module which just consists of the following : sharedArray.jsIn the modules I use it like this : module1.jsmodule2.jsThis works but feels wrong ( useless empty module ) and that I 'm missing something obvious . Is there a better ... | module.exports = [ ] ; var arr = require ( './sharedArray ' ) ; function addSomething ( ) { // Add something to arr } var arr = require ( './sharedArray ' ) ; function doSomething ( ) { // Use arr for something } | Is module.export = [ ] bad practice ? |
JS | The situationI have a React/Redux app that displays markers on a map , and groups them into clusters based on their proximity given the current zoom level ( similar to this example - my app differs from this example slightly in that the clusters on the map will display specific data from their child markers , and not s... | < Map > < Cluster markerIds= [ ... ] / > ... < /Map > { markers : { 1 : { name : 'Bob ' , location : [ -40.08 , 37.62 ] } , 2 : { name : 'Steve ' , location : [ 51.08 , -25.62 ] } , ... } } { markers : { 1 : { name : 'Bob ' , location : [ -40.08 , 37.62 ] } , 2 : { name : 'Steve ' , location : [ 51.08 , -25.62 ] } , ..... | Should a Redux state tree represent how data is organized in the UI ? |
JS | I do n't see anything in the JavaScript spec , the proposed DOM spec extensions related to SharedArrayBuffer , or the current WHAT-WG HTML spec to suggest that shared memory will be synchronized/updated across threads when one thread posts a message to another and the other processes the message . ( After the one has a... | < ! doctype html > < html > < head > < meta charset= '' UTF-8 '' > < title > Sync Test postMessage < /title > < /head > < body > < script src= '' sync-test-postMessage-main.js '' > < /script > < /body > < /html > const array = new Uint32Array ( new SharedArrayBuffer ( Uint32Array.BYTES_PER_ELEMENT ) ) ; const worker = ... | Does ` postMessage ` or yielding to the event loop or similar sync shared memory ? |
JS | ( I 'm sorry if my question title is n't very good , I could n't think of a better one . Feel free to suggest better options . ) I 'm trying to create a reusable `` property grid '' in Angular , where one can bind an object to the grid , but in such a way that presentation of the object can be customized somewhat.This ... | < div ng-repeat= '' prop in propertyData ( { object : propertyObject } ) '' > < div ng-switch on= '' prop.type '' > < div ng-switch-when= '' text '' > < form-element type= '' text '' label-translation-key= '' { { prop.key } } '' label= '' { { prop.key } } '' name= '' { { prop.key } } '' model= '' propertyObject [ prop.... | Binding to arbitrarily deep properties on an object based on rules |
JS | I changed the default placeholder color for my input to blue . Why do I get a black placeholder color with Javascript ? | const getPlaceholderColor = ( ) = > { let inputEl = document.querySelector ( '.myClass ' ) ; let inputElStyle = window.getComputedStyle ( inputEl , ' : :placeholder ' ) ; let resultTarget = document.getElementById ( 'colorResult ' ) ; let placeholderColor = inputElStyle.getPropertyValue ( 'color ' ) ; resultTarget.inne... | Get the correct placeholder color with JS |
JS | Note : This is not a question about classical and prototype inheritance . It 's about what coding patterns to use to initialize objects . Class constructors create and initialize objects , whereas avoiding the new operator and going for Object.create ( ) only creates the object and sets up the prototype chain . I have ... | function Person ( first , last ) { this.name = { first : first , last : last } ; } Person.prototype.tellName = function ( ) { return this.name.first + ' ' + this.name.last ; } var p1 = new Person ( 'John ' , 'Doe ' ) ; var p2 = new Person ( 'Sven ' , 'Svensson ' ) ; p1.tellName ( ) ; // Output : 'John Doe'p2.tellName (... | Coding patterns for initializing objects - constructors ( new ) vs. Object.create ( ) ( Crockford ) |
JS | I 'm trying to call a WebAPI from AngularJS . It is a simple GET request , and I have enabled CORS on the server.I am getting the $ injector : unpr Unknown Provider error.I have an angular module called raterModule.js : a service called corsService.js that uses the snippet from enable-cors.org : ) and finally a control... | var raterModule = angular.module ( 'rater ' , [ ] ) ; raterModule.factory ( `` corsService '' , function createCORSRequest ( method , url ) { var xhr = new XMLHttpRequest ( ) ; // Check if the XMLHttpRequest object has a `` withCredentials '' property . // `` withCredentials '' only exists on XMLHTTPRequest2 objects . ... | AngularJS injector issue |
JS | e.g.And inside the webwoker , assuming there 's quantity of issues to be deal with , would worker.postMessage ( data2 ) block before completing the data1 | worker.postMessage ( data1 ) ; worker.postMessage ( data2 ) ; | Is webworker itself multi-thread ? |
JS | I keep getting back error code : 18 , SecurityError from Edge and Safari while trying to use a Web Worker . The workers are fine in Firefox / Chrome however . I 'm using an inlined worker that I pass zero-dependency data processing functions to.My CSP has looked : I can add in other nice to haves like local stylesheets... | add_header Content-Security-Policy `` default-src 'self ' ; worker-src 'self ' 'inline ' *.example.com '' ; // Create an `` inline '' worker ( 1:1 at definition time ) const worker = new Worker ( // Use a data URI for the worker 's src . It inlines the target function and an RPC handler : 'data : , $ $ ='+asyncFunction... | How to set Content-Security-Policy for Web Workers to work in Edge / Safari ? |
JS | I 'm going to go a bit in-depth with my problem , you can jump to the TL ; DR if you do n't want to read all of thisWhat I 'm trying to doI need to store a `` file '' ( text document ) which can be user-edited . If I have my original file ( which could be huge ) Lorem ipsum dolor sit ametand the user were to make a cha... | var str = 'Original String of text ... '.split ( ' ' ) || [ ] , mod = 'Modified String of text ... '.split ( ' ' ) || [ ] , i , edits = [ ] ; for ( i = 0 ; i < str.length ; i += 1 ) { edits.push ( str [ i ] ===mod [ i ] ? undefined : mod [ i ] ) ; } console.log ( edits ) ; // [ `` Modified '' , null , null , null ] ( d... | Grabbing Edits from two strings |
JS | I am reading the book `` JavaScript for web designers '' and I 've come to this example : The output is : What I do n't get is : where do I tell the program to get the string `` first '' and `` last '' . I mean , cycling the object `` fullName '' , I fail to see how `` name '' can be related to `` first '' and `` last ... | var fullName = { `` first '' : `` John '' , `` last '' : `` Smith '' } ; for ( var name in fullName ) { console.log ( name + `` : `` + fullName [ name ] ) ; } `` first : John '' '' last : Smith '' | For.. in loop - why does it work ? |
JS | I 'm facing a problem with the search . It is a front-end search rather than a remote search , I 'm using react.js because it is a requirement in the problem and created a component named App . My task is to display and highlight the matching parts according to the type value.I will appreciate it . If you provide me a ... | export default [ { id : 1 , name : 'Wordpress ' , list : [ { id : 1 , name : 'Best Mobile App Builder ' , slug : '/ ' } , { id : 2 , name : 'Best Wordpress Themes ' , slug : '/ ' } , { id : 3 , name : 'Best Website Creator ' , slug : '/ ' } , { id : 4 , name : 'Best Wordpress Builder ' , slug : '/ ' } ] } , { id : 2 , ... | React.js search filtration on the array of objects |
JS | This is a twofold question , because I 'm out of ideas on how to implement this most efficiently.I have a dictionary of 150,000 words , stored into a Trie implementation , here 's what my particular implementation looks like : A user is given a provided with two words . With the goal being to find the shortest path of ... | var start = `` dog '' ; var end = `` cat '' ; var alphabet = [ a , b , c , d , e ... . y , z ] ; var possible_words = [ ] ; for ( var letter_of_word = 0 ; letter_of_word < start.length ; letter_of_word++ ) { for ( var letter_of_alphabet = 0 ; letter_of_alphabet < alphabet.length ; letter_of_alphabet++ ) { var new_word ... | Shortest Path between two Trie Nodes |
JS | Say I have the following JS : And the following HTML : Then I 'd like to say this : And I 'd like thisIndex to be a number . How do I turn the string , which is exactly the variable name , into a variable ? | var foo_index = 123 ; var bar_index = 456 ; < div id= '' foo '' > < /div > < div id= '' bar '' > < /div > thisIndex = this.id + '_index ' | Can I refer to a variable using a string ? |
JS | Why is this not working ? ? | var sheep = function ( options ) { this.options = { sizes : 100 , eat : 100 , colors : 'white ' , running : function ( ) { return this.sizes + this.eat ; } } } ; var blacksheep = new sheep ( { colors : 'black ' } ) ; alert ( 'blackcsheep color is ' + blacksheep.colors ) ; //error undefined alert ( 'blackcsheep color is... | How to create a new object in JavaScript ? |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.