Questions tagged [extend]

Cause a unit of code (a class in POO, a style class in CSS ...) to cover a wider area.

Cause a unit of code (a class in POO, a style class in CSS ...) to cover a wider area.

1544 questions
22
votes
3 answers

How can I extend $q promise in Angularjs with a .success and .error

I wrote this little code in a custom service in AngularJS. In my service: var deferred = $q.defer(); var promise = deferred.promise; deferred.resolve('success'); deferred.reject('error'); /* Handle success…
Matohawk
  • 301
  • 3
  • 10
22
votes
2 answers

Python: list.extend without mutating original variable

I am wondering whether there is a way in Python to use .extend, but not change the original list. I'd like the result to look something like this: >> li = [1, 2, 3, 4] >> li [1, 2, 3, 4] >> li.extend([5, 6, 7]) [1, 2, 3, 4, 5, 6, 7] >> li [1,…
Parris
  • 17,833
  • 17
  • 90
  • 133
21
votes
1 answer

PHP : Does extending class need another 'use' to call namespace?

I'm wondering whether in the situation where I'm extending a class that has already 'use' keyword above it to use specific namespace - do I need to add another 'use' above the inheriting class to use the same namespace? Situation like…
Spencer Mark
  • 5,263
  • 9
  • 29
  • 58
20
votes
2 answers

JavaScript cloning a "class" instance

I have a class that goes like this: function Element(){ this.changes = {}; } Now I have an instance of this "Class" like so, el = new Element(). These instances are stored in an array, like elements.push(el). This array of elements is now…
Amit
  • 3,952
  • 7
  • 46
  • 80
20
votes
2 answers

In Swift, how to extend a typealias?

I have a typealias: typealias BeaconId = [String: NSObject] I'd like to extend it by doing something like: extension BeaconId {} But this throws a compile error: Constrained extension must be declared on the unspecialized generic type…
abc123
  • 8,043
  • 7
  • 49
  • 80
20
votes
4 answers

Add properties to stdClass object from another object

I would like to be able to do the following: $obj = new stdClass; $obj->status = "success"; $obj2 = new stdClass; $obj2->message = "OK"; How can I extend $obj so that it contains the properties of $obj2, eg: $obj->status //"success" $obj->message…
Florin
  • 2,891
  • 4
  • 19
  • 26
19
votes
2 answers

Reusing styles in SASS/SCSS without merging selectors

If I have a style definition in SCSS that looks like this: #someid { ... .message { ... &.error { // overrides of .message class } } } So I display some kind of messages in my UI which can be normal…
Robert Koritnik
  • 103,639
  • 52
  • 277
  • 404
19
votes
2 answers

Issue: Audit usage of navigator.userAgent, navigator.appVersion, and navigator.platform

I started a new project in vue.js. I added navbar. At one point, I noticed issue in the console: Audit usage of navigator.userAgent, navigator.appVersion, and navigator.platform I don't understand this, because I don't use any navigator in the…
Weronika
  • 370
  • 1
  • 4
  • 16
19
votes
5 answers

how to get newtonsoft to deserialize yes and no to boolean

NOTE: I have provided the solution at the bottom of this feed. I have a C# Win 8 app where I'm de-serializing some json that looks like this: { 'Unit': [ { 'name':'House 123', isAvailable:'no' }, …
CodeChops
  • 1,980
  • 1
  • 20
  • 27
19
votes
2 answers

Android - Change Holo theme default blue color

I would like to customize Holo theme by changing the default blue color to fit my company color. Is there an easy way to do this? Or I have to redefine the style of all components with blue parts, such as dialog titles, actionbar bottom line, pushed…
Silvia
  • 204
  • 1
  • 2
  • 7
18
votes
3 answers

Extending a java ArrayList

I'd like to extend ArrayList to add a few methods for a specific class whose instances would be held by the extended ArrayList. A simplified illustrative code sample is below. This seems sensible to me, but I'm very new to Java and I see other…
foosion
  • 7,619
  • 25
  • 65
  • 102
18
votes
3 answers

Cucumber class extending step definitions and hooks

I want to extend from a "AbstractBase_step" class in java. So I want to have a hook like: public abstract class AbstractBase_Steps { protected Scenario scenario; @Before public void background(Scenario scenario) { this.scenario =…
user24502
  • 1,662
  • 4
  • 16
  • 21
18
votes
2 answers

jQuery fn.extend ({bla: function(){}} vs. jQuery.fn.bla

OK I think I get Difference between jQuery.extend and jQuery.fn.extend? in that the general extend can extend any object, and that fn.extend is for plugin functions that can be invoked straight off the jquery object with some internal jquery…
Colleen Kitchen
  • 1,069
  • 1
  • 11
  • 20
17
votes
4 answers

What's the difference between mixin() and extend() in Javascript libraries

I'm looking through various libraries, and seeing extend() pop up a lot, but I'm also seeing mixin() show up. YUI has both mixins and extensions. What's the difference between these two concepts? When would I decide between a mixin and extending an…
Matt
  • 22,224
  • 25
  • 80
  • 116
17
votes
1 answer

Javascript, extending ES6 class setter will inheriting getter

In Javascript, with the following illustration code: class Base { constructor() { this._val = 1 } get val() { return this._val } } class Xtnd extends Base { set val(v) { this._val = v } } let x = new Xtnd(); x.val =…
codechimp
  • 1,509
  • 1
  • 14
  • 21