473,625 Members | 3,239 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

EXTEND ?

I switched to using this function to create element:
----------------------------------------------------
function elem(name, attrs, style, text) {
var e = document.create Element(name);
if (attrs) {
for (key in attrs) {
if (key == 'class') {
e.className = attrs[key];
} else if (key == 'id') {
e.id = attrs[key];
} else {
e.setAttribute( key, attrs[key]);
}
}
}
if (style) {
for (key in style) {
e.style[key] = style[key];
}
}
if (text) {
e.appendChild(d ocument.createT extNode(text));
}
return e;
}
---------------------------------------------------------
so instead of the "old" way:
var oMyDiv = document.create Element("DIV");
oMyDiv.setAttri bute("id","test id");
oMyDiv.classNam e = "testclass" ;

I use that function :
var oMyDiv = elem('DIV', {'id':'testid', 'class':'testcl ass'});

The rendered source shows this:
<div extend=" function (object) {return Object.extend.a pply(this, [this,
object]); } "
class="testclas s" id="testid">
Question: I don';t understand the "EXTEND" part......anywa ys does it look
legit/right ?
Any if you please put this "extend=" function (object) {return
Object.extend.a pply(this, [this, object]); } "
in English ;)

thanks
Sep 24 '05 #1
2 1765
Boobie wrote:
Any if you please put this "extend=" function (object) {return
Object.extend.a pply(this, [this, object]); } "
in English ;)


Here's some info on the Object.apply method:

http://developer.mozilla.org/en/docs...Function:apply
JW

Sep 24 '05 #2
"Boobie" <bo********@mai lnull.com> writes:
function elem(name, attrs, style, text) { for (key in attrs) { .... e.setAttribute( key, attrs[key]); .... var oMyDiv = elem('DIV', {'id':'testid', 'class':'testcl ass'});
.... giving:
<div extend=" function (object) {return Object.extend.a pply(this, [this,
object]); } "
class="testclas s" id="testid"> Question: I don';t understand the "EXTEND" part......anywa ys does it look
legit/right ?


It seems you have givent the Object.prototyp e an extra property, i.e.,

Object.prototyp e.extend = function(object ) {
return Object.extend.a pply(this, [this, object]);
};

Since that means that *all* objects inherit the "extend" property,
also your "attrs" object will have it, so it has three attributes:
"id", "class" *and* "extend". The last one is a function, which
gives the value you see when it is converted to a string.

This is a good example of why extending Object.prototyp e is dangerous,
and should only be done with extreme care, since all other code running
in the same environment should know about it.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Sep 24 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
7676
by: sdhyok | last post by:
I think the two script should produce the same results, but not. Why? ---------------- Script #1 ls = ls.extend() print ls -> --------------- Script #2
2
1507
by: Charles Fineman | last post by:
Say i've got a type that appears in a request... say it represents a shipment. I want it to contain things like from and to address elements as well as a sequence of the pieces being shipped. Say the operation is supposed to calculate the cost to ship each piece. I would like the response type to look just like the request type but with a price element under each of the item types. For example: Request: <shipment>
3
8642
by: Alan Little | last post by:
I have a two-column layout, with a background image in the left panel. If the content of the right column is longer than the left, I would like to have the background image repeat all the way down. Is there a way to do this? Here's a screenshot of what I have: http://www.holotech.net/images/brr.jpg My CSS: #TwoColumn {
1
4350
by: Mike Chamberlain | last post by:
Hi all. I'm trying to extend the Microsoft Enterprise Library Data Access Application Block (http://msdn.microsoft.com/library/en-us/dnpag2/html/daab.asp?frame=true) to work with a Borland Interbase database. To do this, I copied and renamed the source files for working with a SQL Server database (SqlCommandWrapper.cs/SqlDatabase.cs to InterbaseCommandWrapper.cs/InterbaseDatabase.cs). I then changed all
2
1536
by: Joseph Turian | last post by:
Hi, What is the safest manner to extend search path for modules, minimizing the likelihood of shooting oneself in the foot? The system (which includes scripts and their shared modules) may be checked out in several different locations, but a script in a particular checked-out version of the system should only use modules from that checkout location.
10
2025
by: Jerzy Karczmarczuk | last post by:
Gurus, before I am tempted to signal this as a bug, perhaps you might convince me that it should be so. If I type l=range(4) l.extend() l gives , what else... On the other hand, try
1
1407
by: aaa | last post by:
Im using a datagrid object to view data, Is it possible to extend selected row and show other details at the extended part of the row? If the answer is Y: Is it part of the datagrid's capabilities? (asp.net 2003).
4
3848
by: rick | last post by:
hi Is there a DB2 equivalent of Informix.Extend function? or please help me the best way to create one Thanks rick
3
3577
by: jacobstr | last post by:
I've noticed Object.extend used in a few different ways and I'm having trouble distinguishing why certain usages apply to a given situation. On line 804 Ajax.Base is defined as follows: Ajax.Base = function() {}; Ajax.Base.prototype = { setOptions: function(options) { <...>
0
8259
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8192
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8696
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8637
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8358
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8502
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7188
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
2621
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1504
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.