Here's an ordinary object, defined with an object literal, and unaware of the fact that it is soon going to fall victim to parasitism:
var twoD = {
name: '2D shape',
dimensions: 2
};
A function that creates triangle objects could:
1.Clone the twoD object into an object called that. This can be done in 2.any way you saw above, for example using the object() function or copying all the properties.
3.Augment that with more properties.
Return that.
function triangle(s, h) {
var that = object(twoD);
that.name ='Triangle';
that.getArea = function(){return this.side * this.height / 2;};
that.side = s;
that.height = h;
return that;
}
Because triangle() is a normal function, not a constructor, it doesn't require the new operator. But because it returns an object, calling it with new by mistake will work in exactly the same way.
>>> var t = triangle(5, 10);
>>> t.dimensions
2
>>> var t2 = new triangle(5,5);
>>> t2.getArea();
12.5
Note that that is just a name; it doesn't have a special meaning, the way this does.
分享到:
相关推荐
昨天看了crockford 的一个视频,里面讲解了一下JS的继承方式,按照PPT里面说的,一共分了三类:Prototypal,pseudoclassical,Parasitic Inheritance。 下面主要介绍一下原型继承:When a function object is ...
模拟设计中的寄生器件,胡琳,,寄生无处不在,如果不重视它甚至忽视它的话,它将毁掉整个设计,特别是在模拟电路设计。通过分析电路和cross-section, 我们会发现有时
Stacked shorted patch antenna with tilted parasitic radiator
Parasitic capacitors are formed during normal operational amplifier circuit construction. Operational amplifier design guidelines usually specify connecting a small 20-pF to 100-pF capacitor between ...
Peroxiredoxins from the plant parasitic root-knot nematode Meloidogyne incognita
AEC-Q100-006D:2003 Electro-Thermally Induced Parasitic Gate Leakage Test (GL) - 完整英文电子版(15页).zip
Bandwidth-Enhanced, Compact, Near-Field Resonant Parasitic Filtennas With Sharp Out-of-Band Suppression
We research some properties of parasitic lasing (PL) in the Ti:sapphire chirped pulse amplifier with the crystal diameter of 100 mm. The evolutionary process from the spontaneous emission to the PL ...
此文档详细介绍了静态下的时序如何去分析,如何使得时序符合时序要求,得到更好的设计方案。学习静态时序分析,这个就够了。
The bq500210 supports improved Parasitic Metal Object Detection (PMOD). The controller in real time analyzes the efficiency of the established power transfer using Rectified Power Packets and ...
1/ Capacitors and resistors have parasitic inductance, about 0.4nH for surface mount and 4nH for a leaded component. (电阻和电容有寄生电感,表贴元件大概为0.4nH,大的元件(?含铅元件)大约为4nH) 2/ ...
11. Parasitic Extraction 12. Power Analysis 13. Crosstalk Analysis 14. Electron Migration 15. Timing Analysis 16. Chip Finishing (DFM or DFY) 17. Low-power Techniques 18. Designs Executed ...
The flow provides capability to analyze noise components, propagating through the substrate, the parasitic interconnects and the package. Using this book, the reader can analyze and avoid complex ...
类式继承(class)组合式继承(combination)构造函数式继承(constructor)多继承(multi)寄生式继承(parasitic)寄生组合式继承(parasitic-combination)原型式继承(prototype)> data-structure <js数据结构> design-...
The SPS PV array model implements a PV array...Two small capacitors, connected on the + and - terminals of the PV array, are used to model the parasitic capacitance between the PV modules and the ground.
Advanced low-parasitic compact ESD protection structures for RF and mixed-signal IC's Mixed-mode ESD simulation-design methodologies for design prediction ESD-to-circuit interactions, and more! ...
Modulation of 3 channels of 33, 34, 35MHz plus a parasitic modulation of 100MHz to simulate radio transmitters. Receiver with a band-pass filter followed by synchronous demodulation and low-pass ...
P2P网络上的寄生网架构研究与分析,葛子毅,程绍银,随着P2P技术的发展,P2P网络架构出现了很多新的变化。该文描述了一种新型的网络架构PoP2P--建立在P2P覆盖网之上的寄生网络(Parasitic Over
1/ Capacitors and resistors have parasitic inductance, about 0.4nH for surface mount and 4nH for a leaded component. 2/ If you don"t want a high bandwidth transistor to oscillate place lossy ...
完整英文电子版 AEC-Q100-006D:2003 Electro-Thermally Induced Parasitic Gate Leakage Test (GL)-电热诱导的寄生门漏电测试(GL)。本规范的目的是建立一个可靠且可重复的程序,用于确定表面贴装集成电路对电热...