I wrote a JavaScript library

JerseyFoo

1/g = g-1
Reaction score
40
I wrote a JS whatchamacallit today, let's me do this...
PHP:
		new $('textarea#textarea').merge({
			parent: new $('div.someHolder'),
			rows: 10,
			cols: 30
		});
		$('textarea')[0].value = 'phallus';
		$id('textarea').value += ' override';
		$('#textarea').value += '++';
		
		new $('div#testdiv1');
		new $('div#testdiv2');

		var e = new $('p.fancy');
		e.textContent = 'Look a paragraph';
		e.parent = $('#testdiv2');
Which creates...
PHP:
<div class="someHolder">
	<textarea id="textarea" rows="10" cols="30">phallus override++</textarea>
</div>
<div id="testdiv1"></div>
<div id="testdiv2"></div>
<p class="fancy">Look a paragraph</p>

Works too. Am I doing it rite?

A critic thinks any high schooler with internet's can call themselves a web developer --so- trying to be professional and those dollar signs are rather popular. :D
 

UndeadDragon

Super Moderator
Reaction score
447
IMO that looks like quite a nice syntax to use. By the looks of what you have shown, it would be easy to dynamically create a whole page with your library.

The only things which don't seem to do anything (that I can see) are:

Code:
$('textarea')[0].value = 'phallus';
        $id('textarea').value += ' override';
        $('#textarea').value += '++';
 

JerseyFoo

1/g = g-1
Reaction score
40
Testing the multiple ways to access an element there -- it works -- just doesn't show up in Chrome's html view. I added it to the main post.

Going off a post for "Beautiful Element Creation in jQuery" I ran a comparison in Firebug with this code...
PHP:
		var e = $('<textarea />', {
			id: "textarea",
			rows: 10,
			cols: 30
		});
		var e2 = $('<div />', {
			class: "someHolder"
		});
		e.appendTo(e2);
		e2.appendTo(document.body);
	
		$('textarea')[0].value = 'phallus';
		// $('#textarea').value += ' override'; // NO WORK
		$('textarea')[0].value += ' override';
		// $('#textarea').value += '++'; // NO WORK
		$('textarea')[0].value += '++';

		$('<div />', {
			id: "testdiv1"
		}).appendTo(document.body);
		
		$('<div />', {
			id: "testdiv2"
		}).appendTo(document.body);	
	
		e = $('<p />', {
			class: "fancy"
		});
		e.text('Look a paragraph');
		e.appendTo(document.body);
Implicit.js (this); 3.1 ms , 29 calls
jQuery-1.5.1.js; 7.2 ms , 550 calls

Consistently, with no optimization done on my code yet.
 

Magentix

if (OP.statement == false) postCount++;
Reaction score
107
I would steer far away from combining dollar signs and CSS selectors, as a lot of people will confuse your work for jQuery.

Also: calling the following two lines without a variable to store them in will instantly destroy the objects
PHP:
		new $('div#testdiv1');
		new $('div#testdiv2');

Finally, textContent is indeed the W3C standard, but a lot of browsers (almost all but Firefox) use innerText instead.
Did you normalize that, or is that an oversight?

I may be mistaken here, but it looks as if there is supposed to be some "generate()" call after your code.
Otherwise, it would be quite weird to be able to set a property and have it update automatically in the DOM.

Anyways, nice work so far, didn't mean to drop an A-bomb on your work here :)
 

JerseyFoo

1/g = g-1
Reaction score
40
Did you normalize that, or is that an oversight?
Was wondering if someone would point that out, yes I normalized it. No generate call needed either, this is why I call it Implicit. I don't want to reveal how all this is possible yet, but it's fast :D

Also: calling the following two lines without a variable to store them in will instantly destroy the objects
Yet it works, crazy yes? Script assumes document.body as a parent if none is given.

I plan to expand support for CSS3 selectors with the exception of descendant, pseudo, and maybe attribute.
 

Magentix

if (OP.statement == false) postCount++;
Reaction score
107
Yet it works, crazy yes? Script assumes document.body as a parent if none is given.

That's actually bad practice.

If someone's stupid enough to initialize objects without assigning them to a reference value,
he'll most likely be stupid enough to forget about those objects and cause (perhaps massive) memory hogs.

Also: unless the parent (document.body) has a reference to its children, the object will still be destroyed on account of being out of scope.
Secondly, if you start mixing JS objects with DOM objects, proceed carefully, as IE handles the latter as COM objects which are garbage collected by reference count.

In other words: having a JS object reference a DOM object may cause a memory leak if you're not careful.
 

JerseyFoo

1/g = g-1
Reaction score
40
Alright I'll reveal the secret; timeouts. Bad programming practice yes, but when combined with the bad practices of most web developers it actually makes for much more efficient code.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top