extend

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

…衆ロ難τιáo~ 提交于 2019-11-27 01:37:26
问题 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 object? Thanks, Matt 回答1: Mixins don't work with instanceof but extends do. Mixins allow multiple inheritance but by faking it, not by properly chaining the prototypes. I'll show an Ext-JS example but the concept applies to any class library that

Can you extend ArrayList in Java?

喜夏-厌秋 提交于 2019-11-27 01:31:02
问题 Is it possible to make a child class that extends ArrayList? If so, how? 回答1: You can extend any class that is not final in Java. Having said that, you should avoid inheritance if there is no true is-a relationship. Consider composition for reuse. Read about Liskov substitution principle 回答2: Yes you can. public class MyArrayList<E> extends ArrayList<E> { } However, I'm not sure why you would want to do this. 回答3: As many other have said, yes, you can extend class ArrayList , but it is not

Javascript: Extend a Function

强颜欢笑 提交于 2019-11-26 22:29:37
问题 The main reason why I want it is that I want to extend my initialize function. Something like this: // main.js window.onload = init(); function init(){ doSomething(); } // extend.js function extends init(){ doSomethingHereToo(); } So I want to extend a function like I extend a class in PHP. And I would like to extend it from other files too, so for example I have the original init function in main.js and the extended function in extended.js . 回答1: With a wider view of what you're actually

How to create simple jQuery plugin?

不羁的心 提交于 2019-11-26 21:56:46
问题 This test plugin, is supposed to work like this: When an element is clicked, it moves down. Simple as that. jQuery.fn.moveDown = function(howMuch){ $(this).css("border", "1px solid black"); $(this).click(function(){ $(this).css("position", "relative"); $(this).animate({top: '+='+howMuch}); }); } The problem is, when an element is clicked, it not only moves the clicked element but also ALL the other elements which the plugin was applied to. What is the solution for this? 回答1: For plugin

Scala, Extend object with a generic trait

拥有回忆 提交于 2019-11-26 21:50:45
问题 I'm using Scala and I want to extend a (singleton) object with a trait, which delivers a data structure and some methods, like this: trait Tray[T] { val tray = ListBuffer.empty[T] def add[T] (t: T) = tray += t def get[T]: List[T] = tray.toList } And then I'll would like to mix-in the trait into an object, like this: object Test with Tray[Int] But there are type mismatches in add and get : Test.add(1) // ... How can I'll get this to work? Or what is my mistake? 回答1: The problem is that you're

Is it possible to extend a class dynamically?

浪子不回头ぞ 提交于 2019-11-26 20:33:34
问题 I have a class which I need to use to extend different classes (up to hundreds) depending on criteria. Is there a way in PHP to extend a class by a dynamic class name? I assume it would require a method to specify extension with instantiation. Ideas? 回答1: I don't think it's possible to dynamically extend a class (however if I'm wrong I'd love to see how it's done). Have you thought about using the Composite pattern (http://en.wikipedia.org/wiki/Composite_pattern, http://devzone.zend.com

how to get newtonsoft to deserialize yes and no to boolean

泪湿孤枕 提交于 2019-11-26 18:31:48
问题 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' }, { 'name':'House 456', isAvailable:'yes' }] } into a class that uses this interface: public interface IUnit { string Name { get; } bool isAvailable { get; } } But Newtonsoft throws an error: Unexpected character encountered while parsing value: n. Path 'Unit[0].isAvailable, line 1, position 42. Is

Laravel extend Form class

*爱你&永不变心* 提交于 2019-11-26 16:38:18
问题 I'm trying to extend the Form class in L4.1 but I seem to be missing something. My file is named FormBuilder.php based on the API and is saved in app/libraries/extended/FormBuilder.php . <?php namespace Extended; class FormBuilder extends \Illuminate\Html\FormBuilder { /** * Create a text input field. * * @param string $name * @param string $value * @param array $options * @return string */ public function text($name, $value = null, $options = array()) { $options = $options + array('id'=>

What is the syntax to insert one list into another list in python?

折月煮酒 提交于 2019-11-26 15:54:39
Given two lists: x = [1,2,3] y = [4,5,6] What is the syntax to: Insert x into y such that y now looks like [1, 2, 3, [4, 5, 6]] ? Insert all the items of x into y such that y now looks like [1, 2, 3, 4, 5, 6] ? Paolo Bergantino Do you mean append ? >>> x = [1,2,3] >>> y = [4,5,6] >>> x.append(y) >>> x [1, 2, 3, [4, 5, 6]] Or merge? >>> x = [1,2,3] >>> y = [4,5,6] >>> x + y [1, 2, 3, 4, 5, 6] >>> x.extend(y) >>> x [1, 2, 3, 4, 5, 6] The question does not make clear what exactly you want to achieve. List has the append method, which appends its argument to the list: >>> list_one = [1,2,3] >>>

Can I extend the console object (for rerouting the logging) in javascript?

做~自己de王妃 提交于 2019-11-26 14:16:24
问题 Is it possible to extend the console object? I tried something like: Console.prototype.log = function(msg){ Console.prototype.log.call(msg); alert(msg); } But this didn't work. I want to add additional logging to the console object via a framework like log4javascript and still use the standard console object (in cases where log4javascript is not available) in my code. Thanks in advance! 回答1: Try following: (function() { var exLog = console.log; console.log = function(msg) { exLog.apply(this,