SlideShare a Scribd company logo
1 of 19
Download to read offline
ENUMERABLE.JSENUMERABLE.JSENUMERABLE.JSENUMERABLE.JSENUMERABLE.JSENUMERABLE.JS
ES5 IS NOT OPERATING ON NATIVE OBJECTS
WE CAN'T CALL ES5 METHODS IN OBJECT CONTEXT
alert([].map.call({head:15,title:30},function(s){return s+'px'}).join(', '))
SOMETIMES WE CAN, HOLY GRAIL..
var o={foo:"foo"}
Array.push(o, 'foo');
Array.push(o, bar);
alert( o.toSource() );//prints:({foo:"foo", length:1, 1:"bar"})
SOMETIMES WE MISUNDERSTOOD ARGUMENTATIONS
var r=
[
{id:0,title:'poem'}
].
filter(function(book){
alert(book.id+" : "+book.title+" : "+this.author);
return book.id==4
},
{author:'Shakespeare'});
WHERE HAS MY AUTHORS DISAPPEARED?
r.forEach(function(book){
alert(book.id+" : "+this.author);//prints 0+" : "+undefned
})
"HOW ABOUT EMULATING AN ARRAY INSIDE AN OBJECT?"
@Angus Croll
WE WILL HAVE TROUBLE WITH LENGTH
LET'S ITERATE THROUGH OBJECT TO MIMIC INDEX
var index = 0;
for(var prop in this){
if(!this.__lookupGetter__(prop) &&
this.constructor!=Array){
(function(thisIndex, thisProp){
Object.defineProperty(obj, thisIndex, {
get: function(){return obj[thisProp]}
, enumerable: true
, configurable: true
, writeable: true
});
})(index, prop)
index++;
}
}
UPDATE OBJECT
Object.defineProperty(obj, 'length', {
get: function(){
return obj.update();
}
set: function(){
return obj.update();
}
, configurable : false
, enumerable : false
, writeable : true
});
obj.length;
CCCHHHEEECCCKKK TTTHHHEEE SSSOOOUUURRRCCCEEE DDDUUUDDDEEE!!!
WORKS?
var myObj={jozsi:2,tamas:5};
//wrap up our object extensional expressions to a method;
extendObj_as_array(myObj);
alert('myObj is now an emulated kind of array '+myObj.length);
//adding new, uninitialized property also as array indices;
myObj.aron=0;
NO...
//it is not possible to query the newly added index to myObj,
//because index is actually uninitialized until the length is queried;
alert('newly added index is undefined: '+myObj[2]);
//length is queried, indices are being updated!
alert('indices are updated: '+myObj.length);
//Now it is possible to query the newly added index to myObj;
alert('newly added index is now defined: '+myObj[2]);
//array functionality works on objects;
alert('mapping values as pixels: '+
[].map.call(myObj,function(s){return s+'px'}).join(', '));
//prints "2px, 5px, 0px"
OBJECT IS KEY-VALUE PAIR RETAINING THE ORDER
SO ENCAPSULATE DIFFERENCES!
var enum=enumerable();
var enum=enumerable([]);
var enum=enumerable({});
var enum=enumerable(new enumerable);
LET US WORK!
//note! vacuum.db.tables[table] is a valid JavaScript Object.
enumerable(vacuum.db.tables[table]).
sort({againstVal:true,func:function(a,b){return a.frequency<b.frequency}}).
.forEach(function(i,val){
if(it.isTypeOf(val,[Object]).
ANDNOT({macro:'$this.id=='+self.defaultRecord}).true())
{
self.record(table,val.id);
}
return true;
});
FEATURES & PRINCIPLES
functional break support
Undo-redo transactions
Recursion support
returning interface consistency
Rock solid ordering management
FEATURES BASED ON ORDERING
Comparison between different types
Order based comparisons
fromItem/toItem support(bubbling)
BIBLIOGRAPY
Angus Croll
HTMLpiknik
Problems with extending regular Objects
enumeration order guarantee

More Related Content

What's hot

Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
Sway Wang
 

What's hot (18)

The Lesser Known Features of ECMAScript 6
The Lesser Known Features of ECMAScript 6The Lesser Known Features of ECMAScript 6
The Lesser Known Features of ECMAScript 6
 
Yahoo! JAPANとKotlin
Yahoo! JAPANとKotlinYahoo! JAPANとKotlin
Yahoo! JAPANとKotlin
 
07 php
07 php07 php
07 php
 
Functional Pe(a)rls - the Purely Functional Datastructures edition
Functional Pe(a)rls - the Purely Functional Datastructures editionFunctional Pe(a)rls - the Purely Functional Datastructures edition
Functional Pe(a)rls - the Purely Functional Datastructures edition
 
An Elephant of a Different Colour: Hack
An Elephant of a Different Colour: HackAn Elephant of a Different Colour: Hack
An Elephant of a Different Colour: Hack
 
Tallerpractica
TallerpracticaTallerpractica
Tallerpractica
 
Exploring slides
Exploring slidesExploring slides
Exploring slides
 
Functional perl
Functional perlFunctional perl
Functional perl
 
Functional pe(a)rls: Huey's zipper
Functional pe(a)rls: Huey's zipperFunctional pe(a)rls: Huey's zipper
Functional pe(a)rls: Huey's zipper
 
Intoduction to php arrays
Intoduction to php arraysIntoduction to php arrays
Intoduction to php arrays
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
Python легко и просто. Красиво решаем повседневные задачи
Python легко и просто. Красиво решаем повседневные задачиPython легко и просто. Красиво решаем повседневные задачи
Python легко и просто. Красиво решаем повседневные задачи
 
Introduction of ES2015
Introduction of ES2015Introduction of ES2015
Introduction of ES2015
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tour
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tour
 
Try PostgreSQL on linux
Try PostgreSQL on linuxTry PostgreSQL on linux
Try PostgreSQL on linux
 
... now write an interpreter (PHPem 2016)
... now write an interpreter (PHPem 2016)... now write an interpreter (PHPem 2016)
... now write an interpreter (PHPem 2016)
 
2016 gunma.web games-and-asm.js
2016 gunma.web games-and-asm.js2016 gunma.web games-and-asm.js
2016 gunma.web games-and-asm.js
 

Viewers also liked (7)

Social Media Workshop - Fredericksburg Chamber
Social Media Workshop - Fredericksburg ChamberSocial Media Workshop - Fredericksburg Chamber
Social Media Workshop - Fredericksburg Chamber
 
Web 30 and RSS
Web 30 and RSSWeb 30 and RSS
Web 30 and RSS
 
Social Networking for Professionals
Social Networking for ProfessionalsSocial Networking for Professionals
Social Networking for Professionals
 
PresentacióN2
PresentacióN2PresentacióN2
PresentacióN2
 
Using RSS feeds for content curation and social scheduling
Using RSS feeds for content curation and social schedulingUsing RSS feeds for content curation and social scheduling
Using RSS feeds for content curation and social scheduling
 
Hippies
HippiesHippies
Hippies
 
Fact About German Thai
Fact About German ThaiFact About German Thai
Fact About German Thai
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Recently uploaded (20)

Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 

Enumerable.js

  • 2. ES5 IS NOT OPERATING ON NATIVE OBJECTS
  • 3. WE CAN'T CALL ES5 METHODS IN OBJECT CONTEXT alert([].map.call({head:15,title:30},function(s){return s+'px'}).join(', '))
  • 4. SOMETIMES WE CAN, HOLY GRAIL.. var o={foo:"foo"} Array.push(o, 'foo'); Array.push(o, bar); alert( o.toSource() );//prints:({foo:"foo", length:1, 1:"bar"})
  • 5. SOMETIMES WE MISUNDERSTOOD ARGUMENTATIONS var r= [ {id:0,title:'poem'} ]. filter(function(book){ alert(book.id+" : "+book.title+" : "+this.author); return book.id==4 }, {author:'Shakespeare'});
  • 6. WHERE HAS MY AUTHORS DISAPPEARED? r.forEach(function(book){ alert(book.id+" : "+this.author);//prints 0+" : "+undefned })
  • 7. "HOW ABOUT EMULATING AN ARRAY INSIDE AN OBJECT?" @Angus Croll
  • 8. WE WILL HAVE TROUBLE WITH LENGTH
  • 9. LET'S ITERATE THROUGH OBJECT TO MIMIC INDEX var index = 0; for(var prop in this){ if(!this.__lookupGetter__(prop) && this.constructor!=Array){ (function(thisIndex, thisProp){ Object.defineProperty(obj, thisIndex, { get: function(){return obj[thisProp]} , enumerable: true , configurable: true , writeable: true }); })(index, prop) index++; } }
  • 10. UPDATE OBJECT Object.defineProperty(obj, 'length', { get: function(){ return obj.update(); } set: function(){ return obj.update(); } , configurable : false , enumerable : false , writeable : true }); obj.length;
  • 12. WORKS? var myObj={jozsi:2,tamas:5}; //wrap up our object extensional expressions to a method; extendObj_as_array(myObj); alert('myObj is now an emulated kind of array '+myObj.length); //adding new, uninitialized property also as array indices; myObj.aron=0;
  • 13. NO... //it is not possible to query the newly added index to myObj, //because index is actually uninitialized until the length is queried; alert('newly added index is undefined: '+myObj[2]); //length is queried, indices are being updated! alert('indices are updated: '+myObj.length); //Now it is possible to query the newly added index to myObj; alert('newly added index is now defined: '+myObj[2]); //array functionality works on objects; alert('mapping values as pixels: '+ [].map.call(myObj,function(s){return s+'px'}).join(', ')); //prints "2px, 5px, 0px"
  • 14. OBJECT IS KEY-VALUE PAIR RETAINING THE ORDER
  • 15. SO ENCAPSULATE DIFFERENCES! var enum=enumerable(); var enum=enumerable([]); var enum=enumerable({}); var enum=enumerable(new enumerable);
  • 16. LET US WORK! //note! vacuum.db.tables[table] is a valid JavaScript Object. enumerable(vacuum.db.tables[table]). sort({againstVal:true,func:function(a,b){return a.frequency<b.frequency}}). .forEach(function(i,val){ if(it.isTypeOf(val,[Object]). ANDNOT({macro:'$this.id=='+self.defaultRecord}).true()) { self.record(table,val.id); } return true; });
  • 17. FEATURES & PRINCIPLES functional break support Undo-redo transactions Recursion support returning interface consistency Rock solid ordering management
  • 18. FEATURES BASED ON ORDERING Comparison between different types Order based comparisons fromItem/toItem support(bubbling)
  • 19. BIBLIOGRAPY Angus Croll HTMLpiknik Problems with extending regular Objects enumeration order guarantee