javascript-objects

Is there an environment-agnostic way to detect Javascript Host Objects?

拈花ヽ惹草 提交于 2019-12-09 10:10:23
问题 I'm writing a Javascript stacktrace library. The library needs to detect wether a particular object or function was created by the programmer or was there as part of the environment (including built-in objects). Host objects are becoming a bit problematic due to their unpredictable behaviour, so I'm after an environment-agnostic way to determine if a particular object in Javascript is a host object (see ECMAScript 3 - 4.3.8). However, distinguishing host objects from native objects and

Finding an object in array and taking values from that to present in a select list

喜夏-厌秋 提交于 2019-12-09 02:36:50
问题 I have a string value (e.g. "Table 1") that I need to use to find a specific object in an array that looks like so: [ { lookups: [], rows: [{data: {a: 1, b: 2}}, {data: {a: 3, b: 4}}], title: "Table 1", columns: [{name: "a"}, {name: "b"}] }, { lookups: [], rows: [{data: {c: 5, d: 6}}, {data: {c: 7, d: 8}}], title: "Table 2", columns: [{name: "c"}, {name: "d"}] } ] Once I have found that object I then need to take the values from the columns key and display them in a select list. I know how to

How to build a menu list object recursively in JavaScript?

让人想犯罪 __ 提交于 2019-12-09 02:28:01
问题 With an array of ['/social/swipes/women', '/social/swipes/men', '/upgrade/premium']; I'd like to construct an map object that looks like: { 'social': { swipes: { women: null, men: null } }, 'upgrade': { premium: null } } const menu = ['/social/swipes/women', '/social/likes/men', '/upgrade/premium']; const map = {}; const addLabelToMap = (root, label) => { if(!map[root]) map[root] = {}; if(!map[root][label]) map[root][label] = {}; } const buildMenuMap = menu => { menu // make a copy of menu //

Iterating over a grid with CasperJS

非 Y 不嫁゛ 提交于 2019-12-08 19:41:49
问题 I am trying to test CasperJS out, and are scraping a site which has a grid layout like: |Name |Name | |Title |Title | |Image |Image | |Something |Something | |---------------------- |Name |Name | |Title |Title | |Image |Image | |Something |Something | |---------------------- If I wasn't using CasperJS I would retrieve a list of all the contains (4 i this case) and then run a method on each container which could retrieve an object with the wanted properties. I just seem to have a hard time of

How can i use Unicode string key In Javascript Object?

╄→尐↘猪︶ㄣ 提交于 2019-12-08 17:06:28
问题 I want to use unicode string in Object as key, something as: var t = {"姓名": "naitong"}; it's ok , t["姓名"] return "naitong" but Object.keys({"姓名": "naitong"}) I got " ", a blank string Anyone knowes why? Editting: I install firebug and try it in the console, it works. Acctually i use mozrepl, so that i can editing and run javascript in emacs. So This have something to do with mozrepl I have confirm that mozrepl support only "7bit safe ASCII", to tranform unicode ,i have to json-encode it in

JavaScript - object's functions referencing its fields

只愿长相守 提交于 2019-12-08 13:48:33
问题 Here is a (very) simplified version of my code: function Ctor() { this.i = 0; this.increment = function() { this.i++; }, this.decrement = function() { this.i--; }, this.display = function() { alert(this.i); } }; The problem is, when the code is run, under some circumstances this now points to something else. I do more or less understand that this changes context from one function to another, but I though my increment function (and the others) would, by the magic of closures, "remember" what

Deleting a row from javascript object

安稳与你 提交于 2019-12-08 11:03:01
问题 I have a javascript object which looks like this :- var myObject = [{"id": "1", "URL": "http://shsudhf.com", "value": "1"}, {"id": "2", "URL": "http://shsusadhf.com", "value": "2"}, {"id": "3", "URL": "http://shsudsdff.com", "value": "0"}]; Now , I have to delete all the rows in the object with id value 2 . How can this be done ? 回答1: If you don't need the original array after "deleting" rows, you can use splice like this: http://jsfiddle.net/rmcu5/1/ var myArray = [{"id": "1", "URL": "http:/

Protractor if ,else with (expect(condition))

天大地大妈咪最大 提交于 2019-12-08 09:50:15
问题 in my script i need to include if and else statement,here is the code if((element(by.model('trt_model')).all(by.tagName('option')).get(0).getText()).toEqual('Select Contract')) { element(by.model('trt_model')).get(1).click(); } else { element(by.model('trt_model')).get(0).click(); } if the expect condition fails , i want the script to execute the else part, but this is not working. when expect condition fails,the script is not executing the else part kindly suggest how this can be resolved

Access public function from private function in JavaScript

回眸只為那壹抹淺笑 提交于 2019-12-08 06:41:03
问题 I have recently started with OOP in JavaScript. And, I am allover confused with these things. I know JavaScript is entirely different from Java. But this is causing problem. What I am trying to implement: function myClass() { //Declare private variable var privateVar = ''; //To act as constructor privateFunction('Hello'); //Getter this.publicFunctionGet = function() { return privateVar; } //Setter this.publicFunctionSet = function(x) { privateVar = x; } function privateFunction(x) { this

Find and retrive object value by key, include nested objects

怎甘沉沦 提交于 2019-12-08 05:23:36
问题 I am trying to find a value by key without knowing the object, include nested object, so the function will get a key and a object and return the value or undefined. This is my function: /* Iterate over object and include sub objects */ function iterate (obj, key) { for (var property in obj) { if (obj.hasOwnProperty(property)) { //in case it is an object if (typeof obj[property] == "object") { if (obj.hasOwnProperty(key)) { return obj[key]; //return the value } } else { iterate(obj[property]);